如何禁用列表框项目 [英] how to disable listbox item

查看:115
本文介绍了如何禁用列表框项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用列表框显示数据库值


我正在使用此代码

i am using listbox to display the database values


i am using this code

private void productlist_Load(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("select productcode,productname from products", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);            
            listBox1.Items.Add("-----------------------------------------------------------------");
            listBox1.Items.Add("Item Code" + "\t\t" + "Item Name");            
            listBox1.Items.Add("-----------------------------------------------------------------");
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
               
                listBox1.Items.Add(ds.Tables[0].Rows[i][0].ToString() + "\t\t" + ds.Tables[0].Rows[i][1].ToString());


            }
            

        }





我想禁用特定项目





i want to disable the particular item

listBox1.Items.Add("Item Code" + "\t\t" + "Item Name");




请帮助我..........




pls hlp me..........

推荐答案

AFAIK,无法禁用标准ListBox对象中的单个项目.
(与旧的ListBox控件不同)
AFAIK, there is no way to disable individual items in a standard ListBox object.
(Unlike the older ListBox control)


您要使用WPF还是Windows窗体?

如果您使用的是Windows窗体,则不可能.您可以尝试通过过滤项目来添加不需要的项目.

如果您使用的是WPF,则数据模板化是一种很好的方法.
Are you using WPF or Windows Forms?

If you''re using Windows Forms, then it isn''t possible. You can try not adding items you don''t want by filtering the items.

If you''re using WPF, data templating is a great approach.




此链接将为您提供帮助.

http://forums.asp.net/p/1477628/3439861.aspx [ ^ ]
Hi,

This link will help you.

http://forums.asp.net/p/1477628/3439861.aspx[^]


这篇关于如何禁用列表框项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆