C#中的下拉列表comboBox问题
我加了this.comboBox1.DrawMode=System.Windows.Forms.DrawMode.OwnerDrawVariable;后,SqlConne...
我加了this.comboBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;后,
SqlConnection conn = new SqlConnection(@"Data Source=./sqlexpress;Initial Catalog=Truck;Persist Security Info=True;User ID=sa;");
SqlDataAdapter adapter = new SqlDataAdapter("SELECT PartNo, NewPart from AutoPart", conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
Dictionary<string, string> d = new Dictionary<string, string>();
comboBox1.DataSource = ds.Tables["cc"];
comboBox1.DisplayMember = "PartNo";
comboBox1.ValueMember = "NewPart";
结果下拉列表显示为System.Data.DataRowView了,倘若System.Windows.Forms.DrawMode.Normal就可以。但是我要用的是上面的那种。该怎样让其正常显示呢
上面发的应为 DataSet ds = new DataSet();
adapter.Fill(ds);
comboBox1.DataSource = ds.Tables[0];
comboBox1.DisplayMember = "PartNo";
comboBox1.ValueMember = "NewPart";意思是一样的 展开
SqlConnection conn = new SqlConnection(@"Data Source=./sqlexpress;Initial Catalog=Truck;Persist Security Info=True;User ID=sa;");
SqlDataAdapter adapter = new SqlDataAdapter("SELECT PartNo, NewPart from AutoPart", conn);
DataSet ds = new DataSet();
adapter.Fill(ds);
Dictionary<string, string> d = new Dictionary<string, string>();
comboBox1.DataSource = ds.Tables["cc"];
comboBox1.DisplayMember = "PartNo";
comboBox1.ValueMember = "NewPart";
结果下拉列表显示为System.Data.DataRowView了,倘若System.Windows.Forms.DrawMode.Normal就可以。但是我要用的是上面的那种。该怎样让其正常显示呢
上面发的应为 DataSet ds = new DataSet();
adapter.Fill(ds);
comboBox1.DataSource = ds.Tables[0];
comboBox1.DisplayMember = "PartNo";
comboBox1.ValueMember = "NewPart";意思是一样的 展开
展开全部
处理comboBox1的DrawItem事件,在相应处理函数里面绘制每个Item。
比如:
this.comboBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.comboBox1_DrawItem);
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawB();
e.DrawFocusRectangle();
e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds);
}
比如:
this.comboBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.comboBox1_DrawItem);
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawB();
e.DrawFocusRectangle();
e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询