我正在表单加载事件上创建网格。最初,我将 datagridview 组合框中的一些值设置为:
Dim dgvc As DataGridViewComboBoxCell
datagrigview1.Rows(0).Cells("Column1").Value = txtColumn1.Text \\setting selected item
datagrigview1.Rows(0).Cells("Column1").Value = txtColumn2.Text
dgvc = datagrigview1.Rows(0).Cells("Column1").Value
dgvc.Items.Add((" ")) \\adding blank
dgvc.Items.Add(txtColumn1.Text) \\then required value
dgvc = datagrigview1.Rows(0).Cells("Column1").Value
dgvc.Items.Add((" "))
dgvc.Items.Add(txtColumn2.Text)
现在,当用户单击特定组合框时。我将其中的新值设置为:
// Resetting old values
If IsDBNull(dgvc) = False Then
dgvc.DataSource = Nothing
dgvc.Items.Clear()
End If
If DtTable.Rows.Count > 0 Then
Dim k As Integer
Dim dgvc1 As DataGridViewComboBoxCell
dgvc1 = New DataGridViewComboBoxCell()
For k = 0 To DtTable.Rows.Count - 1
If DtItemCd.Rows(k)("ItemCd").ToString <> Current_Code Then
datagrigview1.Rows(e.RowIndex).Cells("Column1").Value = DtTable.Rows(k)("Column1").ToString
dgvc1 = datagrigview1.Rows(e.RowIndex).Cells("Column1")
dgvc1.Items.Add(DtTable.Rows(k)("Column1").ToString)
datagrigview1.Rows(e.RowIndex).Cells("Column2").Value = DtTable.Rows(k)("Column2").ToString
dgvc1 = datagrigview1.Rows(e.RowIndex).Cells("Column2")
dgvc1.Items.Add(DtTable.Rows(k)("Column2").ToString)
End If
Next
End If
这显示了旧记录和新记录。请帮助。