-
September 18th, 2007, 03:43 PM
#1
Combo Box issue: Do not show an item
Hi everyone,
I have a data bound combo box as follows:
Code:
m_supplierList.DataSource = database.Tables[0];
m_supplierList.DisplayMember = "Name";
m_supplierList.ValueMember = "ID";
Everything is fine except that there is one particular item that I do not want shown in the box. So, it should still be data bound but one item that I can reference by name or id should not be shown or be disabled.
Does anyone know how I can do this? I tried doing it through the items collection in the same method but that does not seem to work.
Thanks,
xarg
-
September 18th, 2007, 04:05 PM
#2
Re: Combo Box issue: Do not show an item
There aren't many choices. You either remove the items from the combo box or modify the collection.
Since generally it's good programming to separate the presentation from the data, you may want to opt for modifying the collection (i.e. copying only the items you need into a new collection) and then bind it to the control. This approach keeps your UI code simple and keeps the collection manipulation in the data layer.
-
September 18th, 2007, 05:34 PM
#3
Re: Combo Box issue: Do not show an item
Arjay makes a very good point but it could be a little bit of work, depending on the scenario. I've run into similar situations and found it simpler to add a preventive validation after the fact. . .
-
September 18th, 2007, 05:42 PM
#4
Re: Combo Box issue: Do not show an item
Can you set the column width to 0 to hide it?
-
September 18th, 2007, 06:23 PM
#5
Re: Combo Box issue: Do not show an item
Originally Posted by trenches
Arjay makes a very good point but it could be a little bit of work, depending on the scenario. I've run into similar situations and found it simpler to add a preventive validation after the fact. . .
I have had similar problem with a combobox, where all the actual employees are to be shown, but after a while I also have employees in that list which are no longer working for me. For different other reaons I cannot delete them in the database. I solved this very simple adding a column to the database which refers a boolean named 'actual' And this way a simple sql Query allows to only show that employees which are still working for our company. So maybe if you can alter your sql maybe simple excluding the ID of the unwanted item in the query
something like Select * From xyTab where ID > value oR ID < value
and then you bind the resulting recordset to your comobox
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|