I have a combobox
and textbox
using which values are filled into DataGridView
for display purpose. The datagrid
uses SelectionChanged
event.
I am Trying to reflect the same data (when the user moves keys up and down or on mouse click) onto the combobox and textbox on SelectionChanged
event of datagrid
Private Sub DataGridView1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
combobox.Text = DataGridView1.CurrentRow.Cells("DatabaseTable_ColumnName1").Value.ToString()
textbox.Text = DataGridView1.CurrentRow.Cells("DatabaseTable_ColumnName2").Value.ToString()
End Sub
Above code works fine for textbox but not for combobox. In case of combobox, it reflects data of initially selected row only and not the rest. How do I fix this?
i guess you have to use this code for combobox
combobox1.items.add('your string here')
in your situation would be like this :
Private Sub DataGridView1_SelectionChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
combobox1.items.add(DataGridView1.CurrentRow.Cells("DatabaseTable_ColumnName1").Value.ToString())
textbox.Text = DataGridView1.CurrentRow.Cells("DatabaseTable_ColumnName2").Value.ToString()
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.