WPF Datagrid Get Selected Cell Value

前端 未结 12 2092
遇见更好的自我
遇见更好的自我 2020-11-30 08:47

I want to get value for selected cell in datagrid , please anyone tell how to do this. i used SelectedCell changed event , how can i do that?

dataGrid1.Curre         


        
12条回答
  •  甜味超标
    2020-11-30 09:32

    you can also use this function.

     public static void GetGridSelectedView(out string tuid, ref DataGrid dataGrid,string Column)
        {
            try
            {
                // grid selected row values
                var item = dataGrid.SelectedItem as DataRowView;
                if (null == item) tuid = null;
                if (item.DataView.Count > 0)
                {
                    tuid =  item.DataView[dataGrid.SelectedIndex][Column].ToString().Trim();
                }
                else { tuid = null; }
            }
            catch (Exception exc) { System.Windows.MessageBox.Show(exc.Message); tuid = null; }
        }
    

提交回复
热议问题