DataGrid get selected rows' column values

前端 未结 8 1345
你的背包
你的背包 2020-11-27 06:11

I\'m trying to get the values of each column of a selected row in a DataGrid. This is what I have:

private void dataGrid1_CellEditEnding(object sender, DataG         


        
8条回答
  •  日久生厌
    2020-11-27 06:44

    An easy way that works:

    private void dataGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
    {
        foreach (var item in e.AddedCells)
        {
            var col = item.Column as DataGridColumn;
            var fc = col.GetCellContent(item.Item);
    
            if (fc is CheckBox)
            {
                Debug.WriteLine("Values" + (fc as CheckBox).IsChecked);
            }
            else if(fc is TextBlock)
            {
                Debug.WriteLine("Values" + (fc as TextBlock).Text);
            }
            //// Like this for all available types of cells
        }
    }
    

提交回复
热议问题