shax


HI,
Here's my problem... you can't delete a row when the datagridview is in edit mode. Now to make the datagridview useable for the user (e.g selecting from a combo column) you have to set the edit mode to be Edit On Enter otherwise the user has to click the cell to select it and then click it again to edit it. SO now when the user goes to select a row to delete it, it automatically goes into edit mode and so pressing the delete key now will not delete the row. (Should this not a be a simple process or am i missing something )

Can anyone come up with any suggestions

I thought about having a delete button in every row but not sure how to do this

Hope you can help


Thanks


Re: Delete row from datagridview view

Spidermans_DarkSide - MSP, VSIP


Hi,

Try ending the Edit mode.>>

Code Snippet

'You may have to begin and end edit mode

DataGridView1.BeginEdit(True)

DataGridView1.EndEdit(True)

To delete a row use the Remove or RemoveAt method, you may have to use BeginEdit, as above, if the DataGridView is tied to a database. >>>

Code Snippet

Public Class Form1

'This highlighted line should be one line of code in your code window.>>>>

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

DataGridView1.Columns.Add("Column1", "Column1")

DataGridView1.Columns.Add("Column2", "Column2")

'To add 3 rows.

DataGridView1.Rows.Add(3)

'Remove the 2nd row down as

'row counting starts at zero.

DataGridView1.Rows.RemoveAt(1)

End Sub

End Class

Regards,

S_DS






Re: Delete row from datagridview view

shax

Hi,
Thanks for that. Will give it a try. One other question. If i were to use the end edit method I would do this when the user highlights the row by clicking on the record selector for the row. Which event could you use to to determine whether the user has actually selected a row to be deleted

Thanks





Re: Delete row from datagridview view

AbooJCH

There is an event that fires called UserDeletingRow.

Not sure if that would fire before or after your error though. But you might take a look at that one.






Re: Delete row from datagridview view

yowsing

this is how i solve the delete issue. beside setting the endedit value, i also change the editmode back to editonkeystrokeorF2 when user select row header. the editmode will be set back to editOnEnter during the CellEnter event. some how you got to call another event in order for the system to realize your datagridview is changing editmode, therefore i just simply fire the mouseDoubleClick event to achieve this. Hope this is helpful.

Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
DataGridView1.EditMode = DataGridViewEditMode.EditOnEnter
DataGridView1.BeginEdit(True)

End Sub


Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.RowHeaderMouseClick
DataGridView1.EndEdit(True)
DataGridView1.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2
DataGridView1_RowHeaderMouseDoubleClick(sender, e)

End Sub

Private Sub DataGridView1_RowHeaderMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.RowHeaderMouseDoubleClick
DataGridView1.EndEdit(True)

End Sub






Re: Delete row from datagridview view

nelsonl

Thanks yowsing. Your 3-events solution solved the problem for me.