I need some help with following 2 problems -
1. I am using dataGridView control with some databound columns & one unbound column. I populate the databound columns with Dataset etc. and unbound column from a NameValueCollection (basically go row by row) and populate.
I am loading data in the grid during Form load event. All works fine except that unbound column does not get display first time. When I click on refresh button it does come properly. I am using same RefreshData() function from both load & refresh button. I also called dataGridView1.Refresh() but it does not work. Is there anything special I need to do?
2. I also have 2nd problem ( :-( ). I have added UserDeletingRow event (it is done properly and stub was added by .Net) but unfortunately it does not get fired. Am I missing something. Code looks like -
this.dataGridView1.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(this.dataGridView1_UserDeletingRow);
in my .cs code -
private void dataGridView1_UserDeletingRow(object sender, System.Windows.Forms.DataGridViewRowCancelEventArgs e)
DialogResult response = MessageBox.Show("Are you sure you want to delete",
if (response == DialogResult.No)
e.Cancel = true;
Thanks for your post.
1. For displaying data on unbound column and data bound column, it's better to set the DataGridView.VirtualMode property to true, and handle its CellValueNeeded event to display data on unbound cells. For more information, you can check these documents:
2. Setting the SelectionMode of the DataGridView control to FullRoeSelect will do the trick.
this.dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
Hope this helps.
If you have any more questions, please feel free to let me know.Thanks in advance for any feedback.