【问题标题】:trying to sorting the data grid view column shows error message试图对数据网格视图列进行排序显示错误消息
【发布时间】:2011-11-01 09:32:09
【问题描述】:

我有一个带有列的 datagridview

                           customername 
                           customerimage
                           price

当我点击列标题时,整个 datagridview 将被排序,因为我已经尝试了此链接中给出的代码 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);
            }

    }

但是当我点击列标题时它会显示上述消息,即使有一些列有值......

有没有人帮忙解决这个问题....

非常感谢......

【问题讨论】:

  • 您必须向我们展示您如何以及在何处为 newColumn 赋值!!
  • 我正在使用实体框架绑定datagridview .....这与此分开....我刚刚更改了该链接中给出的datagridview的名称..我需要做什么任何其他方法

标签: c# sorting datagridview


【解决方案1】:

问题是当您单击标题时,它没有被选中。 您必须将选择模式设置为列标题选择:

dataGridView1.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;

这必须在调用 dataGridView1_ColumnHeaderMouseClick() 之前完成。你可以把它放在表单的构造函数中,例如放在 onLoad() 中。

【讨论】:

    猜你喜欢
    • 2013-04-22
    • 2015-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-28
    • 2010-10-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多