We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

DataGrid ComboBox Tabbing Problem

I have serched this forum looking for the solution to the WM_KYUP problem when implementing the Combobox inside a datagrid. I am using the DataGridComboBoxColumn class as instructed in the FAQs here at the Syncfusion site. I have also found the faq with the instructions to include the override of the WndProc function but I get an error when I try to include the code in the DataGridComboBoxColumn class. I am fairly new to vb.net and was hoping someone has the solution working and can post the complete code. Regards Jools

1 Reply

MS mstangeh July 12, 2006 08:06 PM UTC

this works for me.. There is a piece of code that I implemented for the combobox too. If you are in a combobox cell in the datagrid, and you press a key it will select te item that starts with the pressed key, if you pressed again than it would serch the next uccurence, and so on.. Code: Option Strict Off Option Explicit On Public Class DataGridComboBoxColumn Inherits DataGridTextBoxColumn Public WithEvents ColumnComboBox As ComboSinKeyUp Private WithEvents _Origen As CurrencyManager Private _RenglonNumero As Integer Private _EsEdicion As Boolean Shared Sub New() End Sub Public Sub New() MyBase.New() _Origen = Nothing _EsEdicion = False ColumnComboBox = New ComboSinKeyUp AddHandler ColumnComboBox.Leave, New EventHandler(AddressOf DejarComboBox) AddHandler ColumnComboBox.SelectionChangeCommitted, New EventHandler(AddressOf ComboComienzaEdicion) AddHandler ColumnComboBox.KeyPress, New System.Windows.Forms.KeyPressEventHandler(AddressOf HandleKeyPress) End Sub Protected Overloads Overrides Sub Edit(ByVal source As CurrencyManager, ByVal rowNum As Integer, ByVal bounds As Rectangle, ByVal readOnly1 As Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean) MyBase.Edit(source, rowNum, bounds, readOnly1, instantText, cellIsVisible) _RenglonNumero = rowNum _Origen = source ColumnComboBox.Parent = Me.TextBox.Parent ColumnComboBox.Location = Me.TextBox.Location ColumnComboBox.Size = New Size(Me.TextBox.Size.Width, ColumnComboBox.Size.Height) ColumnComboBox.Text = Me.TextBox.Text Me.TextBox.Visible = False ColumnComboBox.Visible = True ColumnComboBox.BringToFront() ColumnComboBox.Focus() End Sub Protected Overloads Overrides Function Commit(ByVal dataSource As CurrencyManager, ByVal rowNum As Integer) As Boolean If _EsEdicion Then _EsEdicion = False SetColumnValueAtRow(dataSource, rowNum, ColumnComboBox.Text) End If Return True End Function Private Sub ComboComienzaEdicion(ByVal sender As Object, ByVal e As EventArgs) _EsEdicion = True MyBase.ColumnStartedEditing(sender) End Sub Private Sub DejarComboBox(ByVal sender As Object, ByVal e As EventArgs) If _EsEdicion Then SetColumnValueAtRow(_Origen, _RenglonNumero, ColumnComboBox.Text) _EsEdicion = False Invalidate() End If ColumnComboBox.Hide() End Sub Private Sub HandleKeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) Dim pos As Integer If ColumnComboBox.SelectedIndex > -1 Then If UCase(e.KeyChar) = Left(ColumnComboBox.SelectedItem.ToString.ToUpper, 1) Then pos = busqueda_sig(e.KeyChar) Else pos = busqueda_primero(e.KeyChar) End If Else pos = busqueda_primero(e.KeyChar) End If If pos <> -1 Then ColumnComboBox.SelectedIndex = pos SetColumnValueAtRow(_Origen, _RenglonNumero, ColumnComboBox.Text) End If e.Handled = True End Sub Private Function busqueda_primero(ByVal letra As String) As Integer Dim i As Integer For i = 0 To ColumnComboBox.Items.Count - 1 If letra.ToUpper() = Left(ColumnComboBox.Items(i).ToString.ToUpper, 1) Then Return i End If Next Return -1 End Function Private Function busqueda_sig(ByVal letra As String) As Integer If ColumnComboBox.SelectedIndex < ColumnComboBox.Items.Count - 1 Then ColumnComboBox.SelectedIndex = ColumnComboBox.SelectedIndex + 1 If letra.ToUpper() = Left(ColumnComboBox.SelectedItem.ToString.ToUpper, 1) Then Return ColumnComboBox.SelectedIndex Else Return busqueda_primero(letra) End If Else Return busqueda_primero(letra) End If End Function End Class Public Class ComboSinKeyUp Inherits ComboBox Private WM_KEYUP As Integer = &H101 Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If m.Msg = WM_KEYUP Then ''Ignora el keyup para evita problemas de tabulación Return End If MyBase.WndProc(m) End Sub End Class ''end code. >I have serched this forum looking for the solution to the WM_KYUP problem when implementing the Combobox inside a datagrid. I am using the DataGridComboBoxColumn class as instructed in the FAQs here at the Syncfusion site. I have also found the faq with the instructions to include the override of the WndProc function but I get an error when I try to include the code in the DataGridComboBoxColumn class. > >I am fairly new to vb.net and was hoping someone has the solution working and can post the complete code. > >Regards > >Jools

Loader.
Live Chat Icon For mobile
Up arrow icon