试图对数据网格视图列进行排序会显示错误消息 [英] trying to sorting the data grid view column shows error message

查看:71
本文介绍了试图对数据网格视图列进行排序会显示错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有列的datagridview

I have a datagridview with columns

                           customername 
                           customerimage
                           price

当我单击列标题时,将为整个datagridview排序,因为我尝试了此链接中给出的代码

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;

必须在调用dataGridView1_ColumnHeaderMouseClick()之前完成此操作.例如,您可以将其放在表单或onLoad()的构造函数中.

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

这篇关于试图对数据网格视图列进行排序会显示错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆