Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > RowState changed by just traverse table in DataGridView
 

RowState changed by just traverse table in DataGridView

Hi,

I have question. I have form, on form I gave DataGridView (DGV) on top form and below I have TextBoxes (TB), DatetimePicker. All control bounded to same DataTable. DataGridView can not edit,delete or insert records and designed only to facilitate traversing though rows. all operation to be done in "detail" area which consists Textboxes

So when I just traversing trough records using DGV. I click on three out six record in my DGW. When click on datarow in DGV all values immediately reflected in TB below. Now I click button which run this code

Code Block

private void button1_Click(object sender, EventArgs e)

{

foreach (DataRow dr in this.dsPerson.dtPerson.Rows)

{

Console.WriteLine(dr["Id"] + " | "+ dr.RowState.ToString());

}

}

So it will tell me that all rows which I touched are Modified and rest are Unmodified. Why is that?

My user wants that program checked whether he changed something and forgot to save to I should check from code whether any row got modified but it hard to get truth. As workaround I an checking for Modified record Current and Proposed values for fields, it works butit isreally overkill.

I would appreciate if somebody put some light on it.

Thanks

likhitn  Tuesday, November 20, 2007 8:28 PM
I believe once a cell comes out of edit mode it is marked as changed even if you do not change the value.

Ken Tucker  Wednesday, November 21, 2007 11:53 AM
Hi

Are you sure your other controls do not modify your records? e.g. what if you do not use your dateTimePicker?
Do you use a BindingSource.BeginEdit(); somewhere?
Or any code behind the bindingSource at all?

Are your "detail controls" bound to a bindingSource or a dataSource?

Kind Regards



DamPee  Wednesday, November 21, 2007 12:04 PM

Thanks eveyrbody for replys.

I do not touch "Detail" controls at all while traversing DGV

All controls arebounded to BindingSource (same one)

I am not invoking during traversing any method of BindingSource

Also what I found if your traverse just DGV (no detail controls on form) RowStatereflects reality. I will make today more sophisticated test

likhitn  Wednesday, November 21, 2007 1:51 PM
If you make your datagridview ReadOnly, do you still have the problem?

Kind regards

DamPee  Friday, November 23, 2007 10:52 AM

Hey guys thank you for suggestions.

The DGV was kind of read only since what it allows is only column reordering.

I tried torecreate situation by building simple form with same databinding involved. It turns out that even I have datetimepicker among details it works as predicted on simple form. When you traverse datagridview and even touch details (just click on some of them no editing of course) RowState of datatable is logical - Unmodified. Now I started to think it may be caused by fact that this datatable have a lot of daughter tables which used on same form. I have to dig more. I promise to make investigation in full and post it.

Thanks again

likhitn  Monday, November 26, 2007 11:16 PM

You can use google to search for other answers

Custom Search

More Threads

• How to make multiple rows in a single cell of datagrid?
• Getting the DataRow that corresponds to the CurrentRow of a DataGridView
• Deleting specified column(s) and inserting columns in a DataGridView
• Copy-Paste option in DataGridView
• Validating data in DataGridView
• DataGridView - set Cell.Value for new row, databound
• Typed dataset autoincrement column bound to datagridview, increments unexpectedly
• DatagridvewComboBox - databound lists per row
• howto set "display" text of dg Column headers @ design time?
• Relationship and currency manager