开发者

trying to sorting the data grid view column shows error message

I have a datagridview with columns

                           customername 
                           customerimage
         开发者_开发问答                  price

when i click on the column header the entire datagridview will be sorted for that i have tried the code given in this link http://msdn.microsoft.com/it-it/library/0868ft3z%28v=vs.80%29.aspx

   private void dataGridView1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {

         /// i have just put the code given in that link 

              if (newColumn == null)
              {
    MessageBox.Show("Select a single column and try again.",
        "Error: Invalid Selection", MessageBoxButtons.OK,
        MessageBoxIcon.Error);
            }

    }

but it will shows the above message when i click on the column header even if there are some columns has values ......

would any one pls help on this....

many thanks ......


The problem is when you are clicking the header it is not selected. You must set the selection mode to column header select:

dataGridView1.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;

This must be done before the call of dataGridView1_ColumnHeaderMouseClick(). You can put it in the constructor of the form or onLoad() for example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜