【问题标题】:How to get cell name in this case?在这种情况下如何获取单元名称?
【发布时间】:2017-08-22 17:48:22
【问题描述】:

在标准方法DataBindingComplete 中,我将行/列迭代为:

for (int row = 0; row < dataGridView1.Rows.Count; row++)
{
    for (int column = 0; column < dataGridView1.Columns.Count; column++)
    {
        object value = dataGridView1[column, row].Value;
        if (value != null && value.GetType() == typeof(string))
        {
            (...)
        }
    }
}

如何查看像as这样的单元格名称?

我尝试过这样做:

if (dataGridView1[column, row].Name == "name") 
{
}

编辑 1 当我使用CellFormatting 时,所有单元格在水平滚动后开始跳跃。渲染似乎有问题。看图。

【问题讨论】:

  • 你的意思是列名吗?
  • 你试过dataGridView1.Colums[column].Name。我认为这行得通。
  • 是的,列名
  • 我试过了,但它返回一个错误:System.StackOverflowException occurred HResult=0x800703E9
  • 这可能是一个无限循环。你在if 声明中做什么?

标签: c# winforms c#-4.0 datagridview


【解决方案1】:

连接CellFormatting 事件并尝试使用以下代码更改单元格的值。

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (this.dataGridView1.Columns[e.ColumnIndex].Name == "dataGridViewTextBoxColumn45")
        e.Value = "oleg";
}

【讨论】:

  • 我不能使用 cellFormatting,因为当我滚动数据网格时,它的效果不好。渲染不正确。
  • 看看有问题的图片,当我使用格式化时会发生什么,所有单元格跳转
  • 现在可以使用了
  • 你能检查一下吗?
  • 你可以使用 dropbox 或同等功能吗?
猜你喜欢
  • 2016-04-24
  • 1970-01-01
  • 2017-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-01
  • 2023-01-28
相关资源
最近更新 更多