DataTable dataTable = userLoginDAL.selectRole();
cbRole.ItemsSource = dataTable.DefaultView;
cbRole.SelectedValuePath = "roleId";
cbRole.DisplayMemberPath = "roleName";
参考:https://www.cnblogs.com/liancs/p/3879303.html
举例如下:
DataTable dt = new DataTable();
dt.Columns.Add("name", typeof(string));
DataRow dr1 = dt.NewRow();
dr1[0] = "张三";
dt.Rows.Add(dr1);
DataRow dr2 = dt.NewRow();
dr2[0] = "李四";
dt.Rows.Add(dr2);
DataRow dro=dt.NewRow();
dro[0]="全部";
dt.Rows.InsertAt(dro, 0);
cbxDT.ItemsSource = dt.DefaultView;
cbxDT.DisplayMemberPath = "name";
xaml中不需要其它设置。