Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

modifying how DataGridView works?

Status
Not open for further replies.

moMoney2009

Programmer
Nov 7, 2007
7
US
just trying to make it so that whenever a user wants to add a row they can't do it by using the blank row at the bottom of a DataGridView. I want to make it only available by clicking a Button.

How do I disable the use of the bottom row concept? Or is it not possible?

Thanks
 
answered my own question. Found an event in DataGridView that I didn't notice before until I begun deriving a subclass of DataGridView.

CellBeginEdit

callback method of this event has a type, DataGridViewCellCancelArgs

example:

Code:
private void dataGridView1_RowBeginEdit(object sender, DataGridViewCellCancelArgs e)
{
   if (e.RowIndex >= dataGridView1.Rows.Count)
      e.Cancel = true;
   else
      e.Cancel = false;
}

The reasoning in the IF is that through some testing I figured out that even though the Blank Row is ready for editing it is not counted inside of the .Rows.Count property.
So if the row index is >= to the number of actual rows in the DGV then it MUST be the blank row that is being clicked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top