winforms Infragistics通过Cell Click c#获取名称-属性

zyfwsgd6  于 2022-11-25  发布在  C#
关注(0)|答案(1)|浏览(231)

我已经创建了超过5个网格,其中有一些列是空的/零。这些编号为示例1,2,3...
我已经实现了可以选择和取消选择此列的单个单元格。
现在我的问题是(我对Infragistics仍然非常缺乏经验)

如何仅通过单击即可获得网格的Name Property

我可以读出一些参数,比如cells.index或者rows.index,但是对于另一个方法,我想知道在哪个单元格中点击了Name Property
通过事件处理程序,我让所有的网格进入单元格单击方法

private void GRD_LIST_Grid_ClickCell(object sender, Infragistics.Win.UltraWinGrid.ClickCellEventArgs e)
{
    if (e.Cell.Column.ToString().Contains("BAHN") && e.Cell.Tag == "1") //1-5 Column have the name "BAHN", the Tag is for an flag if the cell is clicked before
    {
        e.Cell.Selected = false;
        e.Cell.Tag = null;
        SetPrio(e.Cell.Row.Index, e.Cell.Column.Index);
    }
    else if (e.Cell.Column.ToString().Contains("BAHN") && e.Cell.Tag == null)
    {
        SetPrio(e.Cell.Row.Index, e.Cell.Column.Index);
        e.Cell.Tag = "1";
    }

    //when the cell is click show the cell in green
    if (e.Cell.Tag == "1")
    {
        e.Cell.Row.Cells[e.Cell.Column.ToString()].Appearance.BackColor = System.Drawing.Color.Green;
    }
    else if (e.Cell.Tag == null)
    {
        e.Cell.Row.Cells[e.Cell.Column.ToString()].Appearance.BackColor = System.Drawing.Color.FromArgb(234,244,243);
    }

    ClearSelectedRow(); //a Method where i set all grids in an array and clear all rows because i dont know which grid i am
}
jvidinwx

jvidinwx1#

ClickCell事件发生时,事件处理程序的第一个参数是sender,在本例中是Infragistics.Win.UltraWinGrid.UltraGrid源。因此,可以像下面的代码那样获取网格名称:

private void GRD_LIST_Grid_ClickCell(object sender, Infragistics.Win.UltraWinGrid.ClickCellEventArgs e)
{
    if (sender is Infragistics.Win.UltraWinGrid.UltraGrid ugrid)
    {
        System.Diagnostics.Debug.WriteLine($"The ClickCell event is raised by '{ugrid.Name}'");         
    }
}

相关问题