How to make a DataGrid work the same,when a user clicks or presses keys

Fiaolle

Member
Joined
Jun 14, 2006
Messages
8
Programming Experience
1-3
Hi
I have a DataGrid with comboboxes (inherited from
DataGridTextBoxColumn) and I'm woundering what methods or something runs when a user clicks in the DataGrid or ComboBox. In the comboboxes I use the KeyUp event for the user to choose an item in the combobox. When I choose an item with keys nothing happens, but when I click and choose an item in my combobox a new row appear in the DataGrid and that is what I want to happen.
Is there someway I can get the same thing to happen whether I click or press
keys in the combobox.


Here is the code for using the keys to choose an item in the comboboxes
VB.NET:
[COLOR=blue][FONT=Courier New]Private[/FONT][/COLOR][FONT=Courier New] [COLOR=blue]Shadows[/COLOR] [COLOR=blue]Sub[/COLOR] IntelliCmb_KeyUp([COLOR=blue]ByVal[/COLOR] sender [COLOR=blue]As[/COLOR] [COLOR=blue]Object[/COLOR], _[/FONT]
[FONT=Courier New][COLOR=blue]ByVal[/COLOR] e [COLOR=blue]As[/COLOR] System.Windows.Forms.KeyEventArgs) [COLOR=blue]Handles[/COLOR] ColumnComboBox.KeyUp[/FONT]
[FONT=Courier New][COLOR=blue]Dim[/COLOR] index [COLOR=blue]As[/COLOR] [COLOR=blue]Integer[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]Dim[/COLOR] actual [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]Dim[/COLOR] found [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]If[/COLOR] ((e.KeyCode = Keys.Back) [COLOR=blue]Or[/COLOR] _[/FONT]
[FONT=Courier New](e.KeyCode = Keys.Left) [COLOR=blue]Or[/COLOR] _[/FONT]
[FONT=Courier New](e.KeyCode = Keys.Right) [COLOR=blue]Or[/COLOR] _[/FONT]
[FONT=Courier New](e.KeyCode = Keys.Up) [COLOR=blue]Or[/COLOR] _[/FONT]
[FONT=Courier New](e.KeyCode = Keys.Down) [COLOR=blue]Or[/COLOR] _[/FONT]
[FONT=Courier New](e.KeyCode = Keys.PageUp) [COLOR=blue]Or[/COLOR] _[/FONT]
[FONT=Courier New](e.KeyCode = Keys.PageDown) [COLOR=blue]Or[/COLOR] _[/FONT]
[FONT=Courier New](e.KeyCode = Keys.Home) [COLOR=blue]Or[/COLOR] _[/FONT]
[FONT=Courier New](e.KeyCode = Keys.ShiftKey) [COLOR=blue]Or[/COLOR] _[/FONT]
[FONT=Courier New](e.KeyCode = Keys.Tab) [COLOR=blue]Or[/COLOR] _[/FONT]
[FONT=Courier New](e.KeyCode = Keys.F2) [COLOR=blue]Or[/COLOR] _[/FONT]
[FONT=Courier New](e.KeyCode = Keys.End)) [COLOR=blue]Then[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]Return[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR][/FONT]
 
[FONT=Courier New][COLOR=blue]If[/COLOR] e.KeyCode = Keys.Enter [COLOR=blue]Or[/COLOR] e.KeyCode = Keys.Delete [COLOR=blue]Then[/COLOR][/FONT]
[COLOR=blue][FONT=Courier New]If[/FONT][/COLOR][FONT=Courier New] ColumnComboBox.Text = "" [COLOR=blue]Then[/COLOR] [/FONT]
[FONT=Courier New]mblnEditing = [COLOR=blue]True[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]Return[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR][/FONT]
 
 
[FONT=Courier New]actual = ColumnComboBox.Text[/FONT]
[FONT=Courier New]index = ColumnComboBox.FindString(actual)[/FONT]
[FONT=Courier New][COLOR=blue]If[/COLOR] (index > -1) [COLOR=blue]Then[/COLOR][/FONT]
[FONT=Courier New]ColumnComboBox.SelectedIndex = index[/FONT]
[FONT=Courier New]ColumnComboBox.SelectionStart = actual.Length[/FONT]
[FONT=Courier New]ColumnComboBox.SelectionLength = found.Length[/FONT]
[FONT=Courier New][COLOR=blue]If[/COLOR] ColumnComboBox.SelectedIndex <> 0 [COLOR=blue]Then[/COLOR][/FONT]
[FONT=Courier New]mblnEditing = [COLOR=blue]True[/COLOR][/FONT]
[FONT=Courier New][COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR][/FONT]
 
 
[FONT=Courier New][COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR][/FONT]
Please, I need help!!!!

Fia
 
Last edited by a moderator:
Top Bottom