c# windows form 的combobox为什么不显示数据呢 comboboxwindows 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 为什么不用SqlDataAdapter ,它绑定数据很方便的啊 如何在ComboBox控件中显示图片和文字示例//用于显示数据的ComboBox设置private ImageList G_ImageList;//声明ImageList字段 private void cbox_DisplayPictures_DrawItem(object sender, DrawItemEventArgs e) { if (G_ImageList != null)//判断ImageList是否为空 { Graphics g = e.Graphics;//得到绘图对象 Rectangle r = e.Bounds;//得到绘图范围 Size imageSize = G_ImageList.ImageSize;//获取图像大小 if (e.Index >= 0)//判断是否有绘制项 { Font fn = new Font("宋体", 10, FontStyle.Bold);//创建字体对象 string s = cbox_DisplayPictures.Items[e.Index].ToString();//得到绘制项的字符串 DrawItemState dis = e.State; if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect)) { e.Graphics.FillRectangle(new SolidBrush(Color.LightYellow), r);//画条目背景 G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index);//绘制图像 e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black),//显示字符串 r.Left + imageSize.Width, r.Top); e.DrawFocusRectangle();//显示取得焦点时的虚线框 } else { e.Graphics.FillRectangle(new SolidBrush(Color.LightGreen), r);//画条目背景 G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index);//绘制图像 e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black),//显示字符串 r.Left + imageSize.Width, r.Top); e.DrawFocusRectangle();//显示取得焦点时的虚线框 } } } }//codego.net/tags/1/1///添加图片文字事件 private void btn_Begin_Click(object sender, EventArgs e) { btn_Begin.Enabled = false;//停用开始按钮 cbox_DisplayPictures.DrawMode = DrawMode.OwnerDrawFixed;//设置绘制元素方式 cbox_DisplayPictures.DropDownStyle = //设置组合框样式 ComboBoxStyle.DropDownList; cbox_DisplayPictures.Items.Add("小车");//添加项 cbox_DisplayPictures.Items.Add("卡车");//添加项 cbox_DisplayPictures.Items.Add("工具");//添加项 cbox_DisplayPictures.Items.Add("朋友");//添加项 G_ImageList = new ImageList();//创建ImageList对象 G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.a);//添加图片 G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.b);//添加图片 G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.c);//添加图片 G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.d);//添加图片 } 是不是要为combox设置一下displaymember this.comboBoxProvince.Items.Add(getdata); 你这样写是不对的,应该 创建一个List< GetData> 集合, while循环的时候 添加数据到集合。while 完之后,绑定combobox的DataSource为list集合,并制定valueMember=“ID”与displayMember =“Name”的值. 不要在comboBoxprovince_SelectedIndexChanged事件里去修改combobo 看错了,还以为你要在combobox的事件里修改自身你做的是级联功能吧断点调试,看哪个传入的参数错误导致查询不出数据呗 c#网站项目调试状态下成功发布提示【未将对象引用设置到对象的实例】 问个很弱智css的问题,连续两个.class是什么意思呢?怎么用呢? 博客或留言板中怎样显示图片 想问下: 我一个lable的text想从数据库返回 怎么办呢? 急!!!! 如何写事件代码? 再求repeater的分页 200分 恳求大家给我提供一个 既能选择日期,又能选择时间(精确到分)得控件或代码 asp.net程序无法运行 新手问:ASP.NET页面的CSS如何定义呢? 问一个简单的问题!我是新手。 求教!ajaxfileupload怎么都用不了! GridView的一个入门问题求解答
//用于显示数据的ComboBox设置
private ImageList G_ImageList;//声明ImageList字段
private void cbox_DisplayPictures_DrawItem(object sender, DrawItemEventArgs e)
{
if (G_ImageList != null)//判断ImageList是否为空
{
Graphics g = e.Graphics;//得到绘图对象
Rectangle r = e.Bounds;//得到绘图范围
Size imageSize = G_ImageList.ImageSize;//获取图像大小
if (e.Index >= 0)//判断是否有绘制项
{
Font fn = new Font("宋体", 10, FontStyle.Bold);//创建字体对象
string s = cbox_DisplayPictures.Items[e.Index].ToString();//得到绘制项的字符串
DrawItemState dis = e.State;
if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect))
{
e.Graphics.FillRectangle(new SolidBrush(Color.LightYellow), r);//画条目背景
G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index);//绘制图像
e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black),//显示字符串
r.Left + imageSize.Width, r.Top);
e.DrawFocusRectangle();//显示取得焦点时的虚线框
}
else
{
e.Graphics.FillRectangle(new SolidBrush(Color.LightGreen), r);//画条目背景
G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index);//绘制图像
e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black),//显示字符串
r.Left + imageSize.Width, r.Top);
e.DrawFocusRectangle();//显示取得焦点时的虚线框
}
}
}
}//codego.net/tags/1/1/
//添加图片文字事件
private void btn_Begin_Click(object sender, EventArgs e)
{
btn_Begin.Enabled = false;//停用开始按钮
cbox_DisplayPictures.DrawMode = DrawMode.OwnerDrawFixed;//设置绘制元素方式
cbox_DisplayPictures.DropDownStyle = //设置组合框样式
ComboBoxStyle.DropDownList;
cbox_DisplayPictures.Items.Add("小车");//添加项
cbox_DisplayPictures.Items.Add("卡车");//添加项
cbox_DisplayPictures.Items.Add("工具");//添加项
cbox_DisplayPictures.Items.Add("朋友");//添加项
G_ImageList = new ImageList();//创建ImageList对象
G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.a);//添加图片
G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.b);//添加图片
G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.c);//添加图片
G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.d);//添加图片
}
while 完之后,绑定combobox的DataSource为list集合,并制定valueMember=“ID”与displayMember =“Name”的值.
你做的是级联功能吧
断点调试,看哪个传入的参数错误导致查询不出数据呗