none
dataGridView columns does not refresh properly

    Question

  •  

    Hi,

     

    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 -

    in designer.cs

    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)
            {
                if (!e.Row.IsNewRow)
                {
                    DialogResult response = MessageBox.Show("Are you sure you want to delete",
                                                "Delete row",
                                                MessageBoxButtons.YesNo,
                                                MessageBoxIcon.Question,
                                                MessageBoxDefaultButton.Button2);
                    if (response == DialogResult.No)
                        e.Cancel = true;
                }
            }

    Tuesday, May 13, 2008 12:12 PM

Answers

  • Hi,

    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:

    http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvalueneeded.aspx

    2. Setting the SelectionMode of the DataGridView control to FullRoeSelect will do the trick. Smile

     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.

    Best Regards
    Zhi-xin Ye

    Monday, May 19, 2008 12:52 PM