3

ユーザーが DataGrid の行をクリックすると、列の値を取得し、その値を使用してデータベースからデータを取得する必要がある WPF アプリケーションを作成しています。

DataGridRow を検索できますが、列の値を取得できません。これが私のコードです...

DataGridRow BillRow = sender as DataGridRow;

選択した行の詳細を BillRow に取得します (ビジュアライザーで表示できます) が、値を変数に取得できません。手伝って頂けますか ??

4

1 に答える 1

3

次の解決策が役立つ場合があります

 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;
     }
于 2013-01-18T11:06:30.360 に答える