Trouble with combobox in DataGrid
-
Hi The first set of source code is the class for a combobox in a grid, hopefully. In the second set of code we try to use the combobox class, but the grid is empty. I don't understand how this works. The first set of code I downloaded from internet and when i tried it, it worked fine. But when I changed the second part of the code it started to give me trouble. Before I changed the code they used Datacolumns,Datarows and Datatables and added them to the Dataset which they used to the Datagrid and it worked fine. I don't understand what is wrong know that I'm using a table I haven't "made" myself but a table I got from a connection. As the third set of code showing, when using comboboxes you can set the Datasource to a table you have connected to with a connection and it works fine, so I think the second part of code should work, but the grid is empty when the program starts. If there is anyone who understand my problem and have a solution, please give me an answer. Thanks Fia 'The MyComboColumn class Imports System.Data Imports System.Drawing Imports System.Collections Imports System.Windows.Forms Namespace ComboBoxTest Public Class MyComboColumn Inherits System.Windows.Forms.DataGridTextBoxColumn Private _cboColumn As ComboBox Private _objSource As Object Private _strMember As String Private _strValue As String Private _bIsComboBound As Boolean = False Private _backBrush As Brush = Nothing Private _foreBrush As Brush = Nothing Private _iRowNum As Integer Private _cmSource As CurrencyManager Public Sub New(ByVal objSource As DataSet, ByVal strMember As String, ByVal strValue As String, ByVal bUseDropDownList As Boolean) '_objSource = objSource _strMember = strMember _strValue = strValue _cboColumn = New ComboBox _cboColumn.DataSource = objSource.Tables(0) _cboColumn.DisplayMember = _strMember _cboColumn.ValueMember = _strValue If bUseDropDownList = True Then _cboColumn.DropDownStyle = ComboBoxStyle.DropDownList Me.ReadOnly = True Else 'AddHandler _cboColumn.KeyPress, AddressOf _cboColumn_KeyPress AddHandler _cboColumn.KeyUp, AddressOf _cboColumn_KeyUp End If AddHandler _cboColumn.Leave, AddressOf cboColumn_Leave _cboColumn.Visible = False End Sub Private Sub _cboColumn_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs) e.Handled = True End Sub Private Shadows Sub _cboColumn_KeyUp(ByVal sender As Object, _ ByVal e As System.Windows.Forms.KeyEventArgs) Dim index As Integer Dim actual As String Dim found As String ' Do nothing for cer