简体   繁体   中英

How to check to which DataColumn a DataGridTextColumn is bound to

I would like to check to which DataColumn a DataGridTextColumn is bound to.

I am trying to do something like:

private void kblMeoravPrDataGrid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
{
     if ((e.Column as DataGridTextColumn).Binding.Path == "DBFieldName")
     {

You should first check that the value isn't null.

var dataGridTextColumn = e.Column as DataGridTextColumn;
if (dataGridTextColumn != null) // If not null then the column is DataGridTextColumn
{
   //working
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM