按钮按下未从 DataGridView 捕获正确的行状态:如何重置或捕获状态?

时间:2021-06-03 14:44:52

标签: vb.net winforms datagridview

代码可以工作,除了一个错误:使用“修改”按钮,它会在 DataGridView 中获取选定的行,如果在第一列数据之前单击左列,则将该数据发送到不同表单上的组合框。

如果用户在 DataGridView 中选择一个单元格或根本不选择,就会出现问题,我让 msgbox 告诉他们选择行。当在该 msgbox 之后选择一行并再次按下“修改”按钮时,DataGridView1.SelectedRows.Count 似乎没有选择它,它仍然是空白的。

奇怪的是,它似乎有 20% 的时间有效。如何设置它以检查状态并确保它选择新的选择?

代码如下:

Private Sub Modify_BTN_Click(sender As Object, e As EventArgs) Handles Modify_BTN.Click
    If (DataGridView1.SelectedRows.Count > 0) Then
        Dim newMod As New Mod_Form
        newMod.ChangeType = DataGridView1.CurrentRow.Cells(8).Value.ToString
        newMod.PartNum = DataGridView1.CurrentRow.Cells(9).Value.ToString
        newMod.PriorityT = DataGridView1.CurrentRow.Cells(10).Value.ToString
        newMod.DESC = DataGridView1.CurrentRow.Cells(11).Value.ToString
        newMod.Show()
    Else
        MsgBox("You did not select the row for the request from the data below, please select the row you want to modify.", MsgBoxStyle.Information)
    End If
End Sub

0 个答案:

没有答案
相关问题