oldhandandy
Programmer
I've created a combox in a datagrid using the code below. The code was taken from Microsoft support and it works OK. I need to substitute the hard coded field list for the dataset 'DsSupplier1'. So far I've been unable to find out how to do this, help would be most appreciated.
------------------------------------------------------------
Public suppcombo As New ComboBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler suppcombo.TextChanged, AddressOf ctrls_textchanged
'//Dataset containing supplier's name
SqlDataSupplier.Fill(DsSupplier1)
suppcombo.Name = "Mycombo"
suppcombo.Visible = False
suppcombo.Items.Clear()
'//hard coded field list
suppcombo.Items.Add("sales reps")
suppcombo.Items.Add("Inside Sales")
DataGrid1.Controls.Add(suppcombo)
End Sub
Private Sub datagrid1_paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles DataGrid1.Paint
If DataGrid1.CurrentCell.ColumnNumber = 1 Then
suppcombo.Width = DataGrid1.GetCurrentCellBounds.Width
End If
End Sub
Private Sub ctrls_textchanged(ByVal sender As Object, ByVal e As System.EventArgs)
If DataGrid1.CurrentCell.ColumnNumber = 1 Then
suppcombo.Visible = False
If DataGrid1.Item(DataGrid1.CurrentCell) & "" = "" Then
SendKeys.Send("*")
End If
DataGrid1.Item(DataGrid1.CurrentCell) = suppcombo.DataSource
End If
End Sub
Private Sub datagrid1_currentcellchanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
If DataGrid1.CurrentCell.ColumnNumber = 1 Then
suppcombo.Visible = False
suppcombo.Width = 0
suppcombo.Left = DataGrid1.GetCurrentCellBounds.Left
suppcombo.Top = DataGrid1.GetCurrentCellBounds.Top
suppcombo.Text = DataGrid1.Item(DataGrid1.CurrentCell) & ""
suppcombo.Visible = True
Else
suppcombo.Visible = False
suppcombo.Width = 0
End If
End Sub
Private Sub datagrid1_scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Scroll
suppcombo.Visible = False
suppcombo.Width = 0
End Sub
Private Sub datagrid1_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
suppcombo.Visible = False
suppcombo.Width = 0
End Sub
------------------------------------------------------------
Public suppcombo As New ComboBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler suppcombo.TextChanged, AddressOf ctrls_textchanged
'//Dataset containing supplier's name
SqlDataSupplier.Fill(DsSupplier1)
suppcombo.Name = "Mycombo"
suppcombo.Visible = False
suppcombo.Items.Clear()
'//hard coded field list
suppcombo.Items.Add("sales reps")
suppcombo.Items.Add("Inside Sales")
DataGrid1.Controls.Add(suppcombo)
End Sub
Private Sub datagrid1_paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles DataGrid1.Paint
If DataGrid1.CurrentCell.ColumnNumber = 1 Then
suppcombo.Width = DataGrid1.GetCurrentCellBounds.Width
End If
End Sub
Private Sub ctrls_textchanged(ByVal sender As Object, ByVal e As System.EventArgs)
If DataGrid1.CurrentCell.ColumnNumber = 1 Then
suppcombo.Visible = False
If DataGrid1.Item(DataGrid1.CurrentCell) & "" = "" Then
SendKeys.Send("*")
End If
DataGrid1.Item(DataGrid1.CurrentCell) = suppcombo.DataSource
End If
End Sub
Private Sub datagrid1_currentcellchanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
If DataGrid1.CurrentCell.ColumnNumber = 1 Then
suppcombo.Visible = False
suppcombo.Width = 0
suppcombo.Left = DataGrid1.GetCurrentCellBounds.Left
suppcombo.Top = DataGrid1.GetCurrentCellBounds.Top
suppcombo.Text = DataGrid1.Item(DataGrid1.CurrentCell) & ""
suppcombo.Visible = True
Else
suppcombo.Visible = False
suppcombo.Width = 0
End If
End Sub
Private Sub datagrid1_scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Scroll
suppcombo.Visible = False
suppcombo.Width = 0
End Sub
Private Sub datagrid1_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
suppcombo.Visible = False
suppcombo.Width = 0
End Sub