首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在WPF中从DataGridRow获取列值

在WPF中从DataGridRow获取列值
EN

Stack Overflow用户
提问于 2013-01-18 18:48:02
回答 1查看 9.4K关注 0票数 3

我正在创建一个WPF应用程序,当用户单击DataGrid的某行时,我需要获取一个列值,并使用该值从数据库中获取数据。

我可以找到DataGridRow,但无法获取列值。这是我的代码。

代码语言:javascript
复制
DataGridRow BillRow = sender as DataGridRow;

我将所选行的详细信息放入BillRow (我可以在Visualiser中看到它们),但无法将值放入变量。你能帮我吗??

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-18 19:06:30

以下解决方案可能会对您有所帮助

代码语言:javascript
复制
 public static DataGridCell GetCell(DataGrid dataGrid, int row, int column)
    {
        DataGridRow rowContainer = GetRow(dataGrid, row);
        if (rowContainer != null)
        {
            DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);

            // try to get the cell but it may possibly be virtualized
            DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
            if (cell == null)
            {
                // now try to bring into view and retreive the cell
                dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);

                cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
            }

            return cell;
        }

        return null;
     }
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14397291

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档