12 Replies - 2123 Views - Last Post: 30 April 2013 - 02:05 PM Rate Topic: -----

#1 Nikoloz999  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 16-April 13

How to grey out some items in combobox

Posted 30 April 2013 - 02:29 AM

I'm writing currency converter program, in which i have 2 same comboboxes, if combobox1 1st item(with index 0) is selected, combobox2 1st item(with index 0) must grey out(unselectable) or must invisible till combobox1 1st item is selected, can some1 help?
Is This A Good Question/Topic? 0
  • +

Replies To: How to grey out some items in combobox

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3575
  • View blog
  • Posts: 11,115
  • Joined: 05-May 12

Re: How to grey out some items in combobox

Posted 30 April 2013 - 05:26 AM

Are you doing this with WinForms, WPF, ASP.NET, Silverlight, or MVC?

For WinForms, you'll want to change DrawMode and do your own painting for the items.

For WPF and Silverlight, the correct way to go about things is to change the item templates and have one of your view model properties bound to the template that determines the rendering style for enabled vs disabled items.

I have no idea how to go about doing this for ASP.NET or MVC.
Was This Post Helpful? 0
  • +
  • -

#3 Nikoloz999  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 16-April 13

Re: How to grey out some items in combobox

Posted 30 April 2013 - 05:53 AM

View PostSkydiver, on 30 April 2013 - 05:26 AM, said:

Are you doing this with WinForms, WPF, ASP.NET, Silverlight, or MVC?

For WinForms, you'll want to change DrawMode and do your own painting for the items.

For WPF and Silverlight, the correct way to go about things is to change the item templates and have one of your view model properties bound to the template that determines the rendering style for enabled vs disabled items.

I have no idea how to go about doing this for ASP.NET or MVC.

I'm doing this in C#
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3575
  • View blog
  • Posts: 11,115
  • Joined: 05-May 12

Re: How to grey out some items in combobox

Posted 30 April 2013 - 06:09 AM

Yes, you are using the C# language, but what are you using for your UI? C# as a language doesn't have it's own UI. You must have picked some way of presenting your UI to your user. I'm asking about which method you chose. Let's try to narrow things down, are you writing your program to run on a web page, or is it a standalone executable?
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: How to grey out some items in combobox

Posted 30 April 2013 - 06:38 AM

If WPF you can set the .IsEnabled property of the menu item to False.
If WinForms the property is .Enabled instead of .IsEnabled.

Wait - my bad - you said combbox, not menu.
Was This Post Helpful? 0
  • +
  • -

#6 Nikoloz999  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 16-April 13

Re: How to grey out some items in combobox

Posted 30 April 2013 - 08:07 AM

View PostSkydiver, on 30 April 2013 - 06:09 AM, said:

Yes, you are using the C# language, but what are you using for your UI? C# as a language doesn't have it's own UI. You must have picked some way of presenting your UI to your user. I'm asking about which method you chose. Let's try to narrow things down, are you writing your program to run on a web page, or is it a standalone executable?

not for web page, its just a program, when i open exe file it starts..
I'm writing this program just for learn how to do it for practice...
Was This Post Helpful? 0
  • +
  • -

#7 Nikoloz999  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 16-April 13

Re: How to grey out some items in combobox

Posted 30 April 2013 - 08:25 AM

if (comboBox1.SelectedIndex == 0) 
................................. // here i must disable 1st item from list of combobox2 (item with index 0)




Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: How to grey out some items in combobox

Posted 30 April 2013 - 08:37 AM

Combobox items don't have a simple .Enabled property in WinForms like they do in WPF. So you're not going to find a simple one line solution for this.

Skydiver gave a direction to research in post #2
Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,466
  • Joined: 29-May 08

Re: How to grey out some items in combobox

Posted 30 April 2013 - 09:11 AM

Wouldn't be easier to not include said items in the list to begin with?
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: How to grey out some items in combobox

Posted 30 April 2013 - 10:09 AM

If the OP wants to make changes at runtime that's not really an option.

Consider what they are making: A currency converter.
So it seems obvious they want to keep the user from trying to convert same items, IE: From US Dollars to US Dollars.

So if US Dollars is selected in the first combobox they want to disable US Dollars from the second combobox.

Again, there is no property for .Enabled with combobox items.

So the best solution I can think of is dynamically loading the second combobox with everything from the first combobox EXCEPT the selected item in the first combobox. Something to the affect of this logic

comboboxFromCurrency_selectedItemChanged(object sender, eventargs e)
{
    foreach item in fromCurrency
    {
        if item is not seleted in fromCurrency
        {
           copy to ToCurrency
        }
     }
}


Note: I'm not giving you code for your homework assignment. I'm giving you logic, a plan. You have to make an attempt to code it.
Was This Post Helpful? 0
  • +
  • -

#11 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,466
  • Joined: 29-May 08

Re: How to grey out some items in combobox

Posted 30 April 2013 - 10:14 AM

tlhIn`toq so how that different to what I said?
Was This Post Helpful? 0
  • +
  • -

#12 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: How to grey out some items in combobox

Posted 30 April 2013 - 10:57 AM

View PostAdamSpeight2008, on 30 April 2013 - 10:11 AM, said:

Wouldn't be easier to not include said items in the list to begin with?


To me this reads as loading the combobox2 items at design-time ("To begin with").
As opposed to dynamically clearing and reloading the items during run-time, every time the user makes a selection from combobox1.

I may have misinterpreted your meaning of "to begin with". Maybe you meant what I just said. It wasn't clear.
Was This Post Helpful? 0
  • +
  • -

#13 Michael26  Icon User is online

  • DIC-head, major DIC-head
  • member icon

Reputation: 355
  • View blog
  • Posts: 1,524
  • Joined: 08-April 09

Re: How to grey out some items in combobox

Posted 30 April 2013 - 02:05 PM

There is always a way of writing your own ComboBox class, but that is longer way around.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1