Editable Combobox in Datagrid

Fiaolle

Member
Joined
Jun 14, 2006
Messages
8
Programming Experience
1-3
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


VB.NET:
Expand Collapse Copy
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:
Please don't double post. Duplicate deleted.

There are lots of discussions and articles and solutions on this subject on the web, I just found this KnowDotNet class that should enable you to add any kind of column type to the DataGrid.
"Multiple Column Formats in Windows Forms DataGrid - KDNGrid Class" http://www.knowdotnet.com/articles/kdngrid.html
 
Back
Top