M
Marc Allard
Hello,
I have a strange problem with the datagridview.
I have a datagridview (filled directly from a datatable).
In the RowEnter Event of the DatagridView, I change the BindingContext of
other elements on the Form (the user can see datas in the datagridView, and
when he goes in one row, he can change values in a textbox. I work like that
because I have some pictures to generate depending on the value of the record.
I must also show a messagebox to the user to ask for him if he want to save
the changes or cancel them.
The problem is that when the user changes something in the textbox, and then
clicks on another row in the DatagridView, the RowEvent triggers two times.
The first event occurs for the current row, and if the current row is
differrent than the new one, the event triggers once again. Of ciurse, I can
live with that, but the problem is that if I show a messagebox to the
customer, the second event never occurs (and so the row never changes). That
is a very big problerm to me as the customer must click two times on the new
row if he has changed something, and only once in nothing has changes.
I have made a small project with the error.
Can you please what I should do to make it work?
To use the sample, you must take a form, and add a datagridview, a textBox
(to change the focus) and a checkbox.
If the checkbox is checked, you can not change the currect row by going from
the text box to another row in the datagridview (the messagebox stops the
event)
Here is the code.
Should I use another event?
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim i As Integer
With DataGridView1
.Columns.Add("Col1", "Col1")
.Columns.Add("Col2", "Col2")
.Columns.Add("Col3", "Col3")
For i = 0 To 5
.Rows.Add()
.Rows(i).Cells("Col1").Value = i + 1
.Rows(i).Cells("Col2").Value = i + 1
.Rows(i).Cells("Col3").Value = i + 1
Next
End With
End Sub
Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
If CheckBox1.Checked Then
MsgBox(e.RowIndex)
Else
Debug.Print(e.RowIndex)
End If
End Sub
Thank you
Marc
I have a strange problem with the datagridview.
I have a datagridview (filled directly from a datatable).
In the RowEnter Event of the DatagridView, I change the BindingContext of
other elements on the Form (the user can see datas in the datagridView, and
when he goes in one row, he can change values in a textbox. I work like that
because I have some pictures to generate depending on the value of the record.
I must also show a messagebox to the user to ask for him if he want to save
the changes or cancel them.
The problem is that when the user changes something in the textbox, and then
clicks on another row in the DatagridView, the RowEvent triggers two times.
The first event occurs for the current row, and if the current row is
differrent than the new one, the event triggers once again. Of ciurse, I can
live with that, but the problem is that if I show a messagebox to the
customer, the second event never occurs (and so the row never changes). That
is a very big problerm to me as the customer must click two times on the new
row if he has changed something, and only once in nothing has changes.
I have made a small project with the error.
Can you please what I should do to make it work?
To use the sample, you must take a form, and add a datagridview, a textBox
(to change the focus) and a checkbox.
If the checkbox is checked, you can not change the currect row by going from
the text box to another row in the datagridview (the messagebox stops the
event)
Here is the code.
Should I use another event?
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim i As Integer
With DataGridView1
.Columns.Add("Col1", "Col1")
.Columns.Add("Col2", "Col2")
.Columns.Add("Col3", "Col3")
For i = 0 To 5
.Rows.Add()
.Rows(i).Cells("Col1").Value = i + 1
.Rows(i).Cells("Col2").Value = i + 1
.Rows(i).Cells("Col3").Value = i + 1
Next
End With
End Sub
Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
If CheckBox1.Checked Then
MsgBox(e.RowIndex)
Else
Debug.Print(e.RowIndex)
End If
End Sub
Thank you
Marc