Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从WPF中的DataGridRow获取列值_C#_Wpf_Wpf Controls_Wpfdatagrid - Fatal编程技术网

C# 从WPF中的DataGridRow获取列值

C# 从WPF中的DataGridRow获取列值,c#,wpf,wpf-controls,wpfdatagrid,C#,Wpf,Wpf Controls,Wpfdatagrid,我正在创建一个WPF应用程序,当用户单击DataGrid的一行时,我需要获取一个列值,并使用该值从数据库中获取数据 我能够找到DataGridRow,但无法获取列值。这是我的密码 DataGridRow BillRow = sender as DataGridRow; 我将所选行的详细信息输入BillRow(我可以在Visualiser中看到它们),但无法将值输入变量。你能帮我吗 以下解决方案可能对您有所帮助 public static DataGridCell GetCell(DataGr

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

我能够找到DataGridRow,但无法获取列值。这是我的密码

DataGridRow BillRow = sender as DataGridRow;

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

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

 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;
     }
公共静态DataGridCell GetCell(DataGrid DataGrid,int行,int列) { DataGridRow rowContainer=GetRow(dataGrid,row); if(rowContainer!=null) { DataGridCellsPresenter=GetVisualChild(行容器); //尝试获取该单元,但它可能已虚拟化 DataGridCell=(DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(列); if(单元格==null) { //现在试着把手机放在视野里,然后拿回手机 ScrollIntoView(rowContainer,dataGrid.Columns[column]); 单元格=(DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(列); } 返回单元; } 返回null; }
>您能帮我吗?数据绑定将帮助您。:)在WPF中没有它很难工作: