wpf 从System.Data.Common.DataRecordInternal中删除值

qjp7pelc  于 11个月前  发布在  其他
关注(0)|答案(2)|浏览(95)

我期待检索的值是绑定到一个sqlexecute查询datagrid。

defects.DefectsDataGrid.DataContext = searchQuery.ExecuteReader();

字符串
然后,我使用SelectedCellsChanged事件对选定的DataGridRow执行一些操作。
当我在中放置断点时,我可以看到System.Data.Common.DataRecordInternal > Non-public Members > _Values下面的值。但我不确定如何引用_Values。
代码

private void DefectsDataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
{
    //Retrieve selected row
    var rows = DefectsDataGrid.SelectedItems;
    
    //This tells me I have one row, which is of type System.Data.Common.DataRecordInternal
    //How do I retrieve the values from this type?
           
}

dgjrabp2

dgjrabp21#

defects.DefectsDataGrid.DataContext = searchQuery.ExecuteReader();

字符串
我将上面的代码更改为下面的代码,这将数据类型改为DataRowView,而不是DataRecordInternal

defects.DefectsDataGrid.ItemsSource = DataTable.DefaultView;


这使我能够轻松地引用事件中的行。

private void DefectsDataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
    {
        //Retrieve selected value from the row selected
        DataRowView dataRow = (DataRowView)DefectsDataGrid.SelectedItem;
        string phrase = dataRow[2];
    }

s71maibg

s71maibg2#

看起来你需要使用DataReader将你的记录转换为IDataRecord
请参阅this answer

相关问题