【问题标题】:DataGridViewCell Get the cell value next to the selected cellDataGridViewCell 获取选中单元格旁边的单元格值
【发布时间】:2013-02-16 14:16:22
【问题描述】:

我有一个包含两列(idDescription)的 DataGridView 表。当用户选择描述列中的单元格时,我希望能够获得左侧单元格旁边的id 值。

这是我目前所拥有的:

    dataGridView1.CellClick += (s, e) =>
        {
            int id;
            DataGridViewCell cell = dataGridView1.SelectedCells[0];

            //Instead of this, what do I put to get the ID column?
            if (cell.ColumnIndex == 0)
                id = Convert.ToInt32(cell.Value);
            else 
                return;

            string[] data = UnitData[id];

            txtNum.Text = id.ToString();
            txtName.Text = data[0];
            txtDesc.Text = data[1];
        };

我希望能够检查选择的列是否是描述,如果是,则获取它旁边的单元格。

我将如何做到这一点?

【问题讨论】:

    标签: c# datagridview


    【解决方案1】:
    if (IsDescriptionColumnIndex)            
    { 
      //Next
      dataGridView1.CurrentCell = dataGridView1[1, e.rowIndex];
    }
    

    【讨论】:

      猜你喜欢
      • 2017-02-22
      • 2020-05-23
      • 1970-01-01
      • 2023-04-02
      • 2018-06-04
      • 2018-04-01
      • 1970-01-01
      • 2021-06-17
      • 1970-01-01
      相关资源
      最近更新 更多