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

DataGridView questions

Hello,

I havea fewquestions about dataGridViews.

1. How can i get the values of current recordwhen changing row?
2. How can i seperate if is a newrow or just changing the data on already existed row?
3. How can i delete a row?

Thank you in advance.
dealwi8me  Sunday, August 23, 2009 4:27 PM
Hi dealwi8me,

The following are the answer to your three questions. If I misunderstood your meaning, please feel free to tell me.

1. You can use dataGridView1.CurrentRow property. It will return the row you are currently selected.

2. RowsAdded event can let you detect when user add a new row to the DataGridview. When you use databinding, you can look up these information in the underline datasource, e.g. A DataTable, the edited row's RowState is Modified while the newly added row's RowState is Added.

3. When you use databinding, you need to remove row from the datasource, e.g. DataTable.Rows.Remove method. When you use unbound situation, you can use DataGridView.Rows.Remove method.

Please tell me if I misunderstood your requirement.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer bydealwi8me Thursday, August 27, 2009 8:13 AM
  •  
Kira Qian  Tuesday, August 25, 2009 7:58 AM
Hi dealwi8me,

The following are the answer to your three questions. If I misunderstood your meaning, please feel free to tell me.

1. You can use dataGridView1.CurrentRow property. It will return the row you are currently selected.

2. RowsAdded event can let you detect when user add a new row to the DataGridview. When you use databinding, you can look up these information in the underline datasource, e.g. A DataTable, the edited row's RowState is Modified while the newly added row's RowState is Added.

3. When you use databinding, you need to remove row from the datasource, e.g. DataTable.Rows.Remove method. When you use unbound situation, you can use DataGridView.Rows.Remove method.

Please tell me if I misunderstood your requirement.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer bydealwi8me Thursday, August 27, 2009 8:13 AM
  •  
Kira Qian  Tuesday, August 25, 2009 7:58 AM
Kira,

thank you for your answer, this is what i was searching. I want to add some code after the user changes row for adding/updating.
I can use RowsLeave as well.


Thanks again!
dealwi8me  Thursday, August 27, 2009 8:13 AM

You can use google to search for other answers

Custom Search

More Threads

• DataGridView Navigator toolbar
• Capture data from datagridview to display into a texbox with a click of a button
• Unlimited creation of columns in DataGridView
• DataGridView Color swapping Problem
• pRINT PROBLEM IN AJAX
• commit changes to database
• BindingSource.CancelEdit does not undelete
• How to bind multiple datatable to a datagrid
• Control.Enabled=False - becomes ugly. Why?
• datagridview checkboxes select with mouse drag