Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > CurrentCellDirtyStateChanged event (Need help)!
 

CurrentCellDirtyStateChanged event (Need help)!

private

void dgView_CurrentCellDirtyStateChanged(object sender, EventArgs e)

{
if (dgView.IsCurrentCellDirty)
{
dgView.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}

I am using this event because i have checkboxes in my datagridview on which i need instant action on its click. This works well for the checkboxes but the problem is when i want to insert a value into one of the cells using my keyboard eg. 10. The event commits the 1 then commits the 0 therefore leaving the value in the cell = to 0. It sets the cell value to 1 then to 0 as you type in 10. That mean when ever I type it erases whole text and replaces it with last typed letter, Hope I am clear to all of you. How canI make this event only operate for my textbox column or any other alternate soltion please!

Laxman Mankala  Wednesday, August 12, 2009 11:11 AM
Hi,

You need to check whether the currentCell is a CheckBoxCell first. If not,don't commit edit.
For example:

void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)

{

if (dataGridView1.CurrentCell is DataGridViewCheckBoxCell)

{

Console.WriteLine("CurrentCell is a DataGridViewCheckBoxCell");

}

}

Please let me know if this helps. If i misunderstood you, please feel free to tell me.

Best regards,
Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, August 18, 2009 7:35 AM
Change it to

private  void dgView_CurrentCellDirtyStateChanged(object sender, EventArgs e){
     if (dgView.IsCurrentCellDirty)
      { 
          dgView.CommitEdit(DataGridViewDataErrorContexts.Commit);
          return;
      }
}

NareshG  Wednesday, August 12, 2009 11:40 AM

Hi Naresh, Thanks for your reply but that doesnt solve the problem :(

Laxman Mankala  Wednesday, August 12, 2009 12:44 PM
Hi Laxman,
Can you post your code, I tried and it worked very well.
And if you dont put return after commit in CurrentCelldirtyStatChanged event , then code below that would execute twice.
NareshG  Wednesday, August 12, 2009 7:39 PM
Hi,

You need to check whether the currentCell is a CheckBoxCell first. If not,don't commit edit.
For example:

void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)

{

if (dataGridView1.CurrentCell is DataGridViewCheckBoxCell)

{

Console.WriteLine("CurrentCell is a DataGridViewCheckBoxCell");

}

}

Please let me know if this helps. If i misunderstood you, please feel free to tell me.

Best regards,
Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, August 18, 2009 7:35 AM

You can use google to search for other answers

Custom Search

More Threads

• Populating DataSets
• Typed Dataset Generator is ignoring DateTimeMode on date columns!?
• Datagridview combo box columns, problem when losing focus - Urgent
• Problem running delete query on remote server
• PropertyChangedEventHandler not firing automatically.
• DataGrid Disabling BindingNavigator Controls
• How to use dropdowns in a Dataset/Datagrid
• Keeping same cell address selected after sorting unbound DataGridView
• Comparing GRID
• problem with DataGrid .net 1.1