在C#DataGrid中双击行的任何列时如何获取行的第一个单元格的内容

问题描述 投票:0回答:1

我想双击任何行的第一个单元格的内容。 (例如,在两种情况下我都想单击cell [row 1,column2]或cell [row 1,column3]时,都想获取cell [row1,column1]的内容)。通过我编写的代码,我可以双击任何单元格的内容。这是我的代码:*'var cellValue'给我单元格的内容。所以,我想在'var cellValue'*中实现cell [row r,column1]的内容和私有列表m_AllDgTag = new List();

我的代码:

private void DgCM_MouseDoubleClick(object sender,MouseButtonEventArgs e){

        int currentPnl = 0;
        if (m_AllDgTag.Count > 1)
        {
            currentPnl = m_CurrentFDS;
        }
        var cellInfo = m_AllDgTag[currentPnl].CurrentCell;

        if (cellInfo != null && m_CurrentStep != null)
        {
            var column = cellInfo.Column as DataGridBoundColumn;

            int cellColIndex = cellInfo.Column.DisplayIndex;


                if (column != null)
                {

                    var element = new FrameworkElement() { DataContext = cellInfo.Item };
                    BindingOperations.SetBinding(element, FrameworkElement.TagProperty, column.Binding);
                    var cellValue = element.Tag;
c# indexing datagrid row cell
1个回答
0
投票

Hasan,应该使用事件RowHeaderMouseDoubleClick代替MouseDoubleClick

© www.soinside.com 2019 - 2024. All rights reserved.