1:打开窗体时,ComBox .Text为空;
2:数据源来源于数据库;
3:下拉选项中,第一选项为空白
1
public
void
BindCmb()
2![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
3
System.Data.DataTable dt = myData.GetMotorType().Tables[0];
4
System.Data.DataRow row = dt.NewRow();
5
row["ID"] = 0;
6
row["类型"] = "";
7
dt.Rows.InsertAt(row, 0);
8
this.CmbDeviceType.DataSource = dt;
9
this.CmbDeviceType.DisplayMember = "类型";
10
this.CmbDeviceType.ValueMember = "ID";
11
this.CmbDeviceType.SelectedIndex = -1;
12
}
即在数据源(DataTable增加一空行)。
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/InBlock.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)