C# 将新行分配给ComboBox的DataSource列
我根据从数据源接收到的数据,以数字方式创建组合框。我有这样的代码:C# 将新行分配给ComboBox的DataSource列,c#,winforms,combobox,C#,Winforms,Combobox,我根据从数据源接收到的数据,以数字方式创建组合框。我有这样的代码: private static ComboBox DoCreateComboBox(DataTable empList, int yPoint, int xComboPoint, DataRow task) { var currentEmpGuid = task["EmpGuid"]; var recalculatedEmpGuid = ""; if (curr
private static ComboBox DoCreateComboBox(DataTable empList, int yPoint, int xComboPoint, DataRow task)
{
var currentEmpGuid = task["EmpGuid"];
var recalculatedEmpGuid = "";
if (currentEmpGuid.Equals(Guid.Empty))
{
recalculatedEmpGuid = "Unassigned";
}
else
{
recalculatedEmpGuid = currentEmpGuid.ToString();
}
//Creating ComboBox
return new ComboBox()
{
DisplayMember = "Name",
ValueMember = "EmpGuid",
BindingContext = new BindingContext(),
DataSource = empList,
SelectedValue = recalculatedEmpGuid,
DropDownStyle = ComboBoxStyle.DropDownList,
Location = new Point(xComboPoint, yPoint),
Tag = task
};
如您所见,我根据收到的Guid
重新计算了值。我想知道如何将未分配的值添加到我的员工列表
,以便在组合框
上用作SelectedValue
属性
为了更简单,我只需要将值为“Unassigned”的新行添加到task[“EmpGuid”]
列中
我怎样才能做到这一点?关于只需在empList数据表中添加或插入行。这是我的问题。我怎样才能做到这一点@LarsTech
DataRow dr=empList.NewRow()代码>设置列数据。然后将其添加到表中:empList.Rows.add(dr)代码>或empList.Rows.Insert(dr,0)代码>