Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid Combox

Status
Not open for further replies.

oldhandandy

Programmer
Sep 25, 2003
5
GB
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
 
Sorry I can't give you a working code example, but it appears that you are already using a DataSet. Instead of
Code:
'//hard coded field list
suppcombo.Items.Add("sales reps")
suppcombo.Items.Add("Inside Sales")
could you create a DataTable, say TempTable, and populate it with your hard coded field list. Then TempTable could become the DataSource for suppcombo and the code should work. Good Luck!

Have a great day!

j2consulting@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top