1

我正在做一个项目,当我在行上单击两次时,我需要读取 Infragistics GridList 中的一行。这就是我填充我的网格列表的方式

     try
        {
            if (txtAd.Text.Replace("'", "").Trim() == string.Empty && txtSoyad.Text.Replace("'", "").Trim() == string.Empty)
            {
                stBarMsg.Text = "ad soyad girilmeli!";
                return;
            }

            DataTable dt = PrePaidLib.getParaPuanGoruntulemeList(true, txtAd.Text.Replace("'", ""), txtSoyad.Text.Replace("'", ""));
            grdList.DataSource = dt;
            grdList.DataBind();
        }
        catch (Exception exp)
        {
            ErrorLib.ErrorHandle(exp, "frmParaPuanGoruntuleme.retrieveRecord");
        }

在这里,你可以找到我的双击功能

        private void grdList_DoubleClickCell(object sender, Infragistics.Win.UltraWinGrid.DoubleClickCellEventArgs e)
    {
        try
        {
            txtKartno.Text = grdList.Selected.Columns[0].ToString();//Cells[1].ToString();
        }
        catch(Exception ex)
        {
            ErrorLib.ErrorHandle(ex, "grdList_DoubleClickCell");
        }
    }

此行不起作用“txtKartno.Text = grdList.Selected.Columns[0].ToString();” 顺便说一句,我想逐个获取每个属性的值。我的网格列表中有 4 列。有什么建议么?

4

1 回答 1

2

当您双击 Infragistics UltraWinGrid 中的单元格时,您会收到在DoubleClickCellEventArgs.Cell属性中单击的单元格。通过该属性,您可以使用语法到达当前行e.Cell.Row,从该行您可以使用语法到达任何其他单元格e.Cell.Row.Cells[columnName or columnIndex].Value

所以你需要的数据可以这样读取

txtKartno.Text = e.Cell.Row.Cells[0].Value.ToString();

(我假设所需的单元格不是单击的单元格,并且该列的索引为零)

当然,如果单击的单元格是您需要的单元格,则语法更简洁

txtKartno.Text = e.Cell.Value.ToString();

要完成答案,请注意,UltraGridRow 有两种方法可用于从行中检索单元格值:

string textResult = e.Cell.Row.GetCellText(e.Row.Band.Columns[0]);
object objResult = e.Cell.Row.GetCellValue(e.Row.Band.Columns[1]);

根据 Infragistics 的说法,这两种方法避免了创建不需要的单元格对象,因此性能更高。就您而言,尚不清楚这些方法是否真的有益。

于 2012-06-26T07:49:21.350 回答