Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6154077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:12:05+00:00 2026-05-23T20:12:05+00:00

In a ComboBox there are some items which have to be enabled and some

  • 0

In a ComboBox there are some items which have to be enabled and some which have to be disabled (and visible).

At first the ComboBox ItemsSource is set:

comboBoxMachine.ItemsSource = machineList;

where comboBoxMachine is a ComboBox and machineList is a List<Machine> (Machine is a custom object)

Later a condition for each machine from the list has to be checked and in case it is fulfilled the appropriate item from the ComboBox has to be disabled.

Below is the combination of code/pseudocode of the logic:

private void modifyMachineComboBoxItems()
    {
        foreach (Machine mch in machineList)
        {
            if (constructionSiteSchedule.ReservationMachinePeriods.Count(x => x.MachineId == mch.Id) > 0) //if this condition is fulfilled, it should be not possible to select the machine from the comboBoxMachine
            {
                int currentPosition = machineList.IndexOf(mch);
                disable the element from the comboBoxMachine at position currentPosition;
            }
        }
    }

What I haven’t figured out so far is how to disable the element from the ComboBox at given position so I would be very thankful if anyone could modify the code above such that the ComboBox items for machines that satisfy the condition are disabled.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:12:06+00:00Added an answer on May 23, 2026 at 8:12 pm

    You should just have boolean property on your machine that corresponds to whether the item is enabled, in your ComboBox.ItemContainerStyle you can bind IsEnabled to that property, then when you want to disable the item just set the property on the machine to false.


    Alternatively you could use the ItemContainerGenerator (which you really should not):

    var item = comboBoxMachine.ItemContainerGenerator.ContainerFromIndex(currentPosition) as ComboBoxItem;
    item.IsEnabled = false;
    

    (You do not need to get the position first by the way as there also is a ContainerFromItem method, also see the comment below)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a combobox which has ItemsSource set to an ObservableCollection property called DATA
I use a datatemplate to visualize some items in a ComboBox, the ItemsSource is
Hi all I have a combobox which is databound to a list of elements.
Are there any professional Combobox controls (dropdown list with autosuggestion) based on the jQuery
is there a more simple way to get combobox (WinForms) selected items text? string
Is there a way to set the .Text property of the Wpf ComboBox control
I have an Combobox which is poplated with data that is time sensitive. My
I have a collection of StackPanel which each one includes a dynamic set of
I have some nested SplitContainers and there is one undesired behaviour happening. Every time
How can I check that a combobox in winforms contains some value? Is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.