Hi
I like to have an editable combobox in my Datagrid, like the one's they have in Access. I've seen some examples on how to add a combobox in a datagrid, but they are not editable. I found an example at page http://www.akadia.com/services/dotnet_combobox_in_datagrid.html, it works OK, but it's not editable and when I tried to add the KeyUp event (below) to the class NoKeyUpCombo it doesn't work. Presumably because of the procedure WndProc. The code below have I used to make an editable combobox an it works fine, but I don't know how to add it to a combobox in a datagrid.
I'm using Microsoft Development Environment 2003, and then can't use DatagridView.
Thankfull for answers
Fia
I like to have an editable combobox in my Datagrid, like the one's they have in Access. I've seen some examples on how to add a combobox in a datagrid, but they are not editable. I found an example at page http://www.akadia.com/services/dotnet_combobox_in_datagrid.html, it works OK, but it's not editable and when I tried to add the KeyUp event (below) to the class NoKeyUpCombo it doesn't work. Presumably because of the procedure WndProc. The code below have I used to make an editable combobox an it works fine, but I don't know how to add it to a combobox in a datagrid.
I'm using Microsoft Development Environment 2003, and then can't use DatagridView.
Thankfull for answers
Fia
VB.NET:
Public Class IntelliCmb
Inherits System.Windows.Forms.ComboBox
Private Shadows Event KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs)
Private Shadows Sub IntelliCmb_Keypress(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
Dim index As Integer
Dim actual As String
Dim found As String
' Do nothing for certain keys such as navigation keys
If ((e.KeyCode = Keys.Back) Or _
(e.KeyCode = Keys.Left) Or _
(e.KeyCode = Keys.Right) Or _
(e.KeyCode = Keys.Up) Or _
(e.KeyCode = Keys.Delete) Or _
(e.KeyCode = Keys.Down) Or _
(e.KeyCode = Keys.PageUp) Or _
(e.KeyCode = Keys.PageDown) Or _
(e.KeyCode = Keys.Home) Or _
(e.KeyCode = Keys.ShiftKey) Or _
(e.KeyCode = Keys.End)) Then
Return
End If
' Store the actual text that has been typed
actual = Text
' Find the first match for the typed value
index = FindString(actual)
' Get the text of the first match
If (index > -1) Then
found = Items(index).ToString()
' Select this item from the list
SelectedIndex = index
' Select the portion of the text that was automatically
' added so further typing will replace it
SelectionStart = actual.Length
SelectionLength = found.Length
End If
End Sub
End Class
Last edited by a moderator: