程序代码:
//可以在selectionchanged事件加入这样的验证代码 if (dataGrid1.SelectedItem == null) return; Dictionary<string, object> dr = IEnumerableToDictionary(dataGrid1.SelectedItem); qh.问题 = dr["问题"].ToString() public static Dictionary<string, object> IEnumerableToDictionary(object o)//单行 { Dictionary<string, object> t = new Dictionary<string, object>(); foreach (System.Reflection.PropertyInfo pi in o.GetType().GetProperties()) { t.Add(pi.Name, pi.GetValue(o, null)); } return t; }