我是使用的DataTable绑定的ComboBox下拉框
public void BindingList(ComboBox cbo,string value,string display,string tableName,string pid)
{
DataTable dt = new DataTable();
dt = DBHelper.GetDT(value, display, tableName,pid);
//DataRow dr = dt.NewRow();
//dr[0] = "-1";
//dr[1] = "--请选择--";
//dt.Rows.Add(dr);
//dt.DefaultView.Sort = value;
cbo.ItemsSource = dt.DefaultView;
cbo.DisplayMemberPath = "VALUE";
cbo.SelectedValuePath = "pid";
}
然后,我想获取到选中项的Value值
private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (comboBox.SelectedItem != null)
{
string a = comboBox.SelectedValue.ToString();
//ComboBoxItem a = (ComboBoxItem)comboBox.SelectedItem;
//string selectText = a.Content.ToString();
}
}
但是获取出来的是System.Data.DataRowView
如果不是这么获取,那应该使用什么方法来获取ComboBox的下拉框Value值呢?