Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView Delete Row
 

DataGridView Delete Row

I prefer to have my DataGridViewset as follows:

SelectionMode = DataGridViewSelectionMode.CellSelect
EditMode = DataGridViewEditMode.EditOnEnter

I am using EditOnEnter as my client likes this method better. I am using CellSelectas I have some cells that I have faked disabling and want the user to be able to see the changes I have made to the background colors in these "disabled" cells.

That being the case, how do I let the user select the full row so that it can be deleted?

Aspnot  Monday, February 13, 2006 9:01 PM

this selects the selected row.

System.Windows.Forms.DataGridViewRow selectedRow = dgv.CurrentRow;

selectedRow.Selected = true;

icemart525  Tuesday, February 14, 2006 5:06 AM

this selects the selected row.

System.Windows.Forms.DataGridViewRow selectedRow = dgv.CurrentRow;

selectedRow.Selected = true;

icemart525  Tuesday, February 14, 2006 5:06 AM
THat makes sense, but where would you put that code? What event would get you there?

michaelloveusa  Tuesday, November 13, 2007 6:18 PM
They can use the row header to select the full row or you can enable FullRowSelect but that may change the way you like to see it.

You could handle the cell click event to select the entire row under whichever circumstances you want.
Kristian PD  Tuesday, November 13, 2007 8:09 PM

Thanks Kristian.

I tried handling the RowHeaderMouseClick event and selecting the entire row, but it didn't work. I posted the problem here:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2404085&SiteID=1

michaelloveusa  Tuesday, November 13, 2007 8:41 PM
I was under the impression that the default operation of selecting the row header will select the entire row regardless if you have CellSelect enabled?

Also, RowHeaderMouseClick won't work - you would need to register for CellClick to achieve what i was describing above.
Kristian PD  Wednesday, November 14, 2007 1:07 PM

Hi Kristian.

Thanks for you response. The response I got back on my other post (listed above) worked like a charm. Here are the details:

Try using the RowHeaderSelect SelectionMode. I believe this will allow you to select the entire row by clicking on the row header, and give you cell focus if you click on a cell.

Mike

michaelloveusa  Wednesday, November 14, 2007 3:48 PM

You can use google to search for other answers

Custom Search

More Threads

• Tree View Help Required
• How to improve performance of datagridview
• VS 2005 - Easiest way to get two related tables in one datagridview?
• CreateDatabase at runtime
• Operation did not succeed because the program cannot commit or quit a cell value change.
• Datagridview / Backgroundworker and Web Service
• Can I bind the CheckedState of a CheckedListBox to my objects?
• DataGridView master detail over intersect/junction table?
• retrieving data from multiple tables in a dataset
• Programmatically scroll a DataGridView control horizontally