在 Selection Changed 事件中将值反映到数据网格中的组合框
reflect values to combo box from datagrid on Selection Changed event
我有一个 combobox
和 textbox
,使用它们将值填充到 DataGridView
以供显示。
datagrid
使用 SelectionChanged
事件。
我正在尝试将相同的数据(当用户上下移动键或单击鼠标时)反映到数据网格 SelectionChanged
事件的组合框和文本框中
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
以上代码适用于文本框但不适用于组合框。
在组合框的情况下,它仅反映最初选择的行的数据,而不反映其余行的数据。
我该如何解决这个问题?
我猜你必须将此代码用于组合框
combobox1.items.add('your string here')
在你的情况下是这样的:
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
我有一个 combobox
和 textbox
,使用它们将值填充到 DataGridView
以供显示。
datagrid
使用 SelectionChanged
事件。
我正在尝试将相同的数据(当用户上下移动键或单击鼠标时)反映到数据网格 SelectionChanged
事件的组合框和文本框中
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
以上代码适用于文本框但不适用于组合框。 在组合框的情况下,它仅反映最初选择的行的数据,而不反映其余行的数据。 我该如何解决这个问题?
我猜你必须将此代码用于组合框
combobox1.items.add('your string here')
在你的情况下是这样的:
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