ComboBox SelectionChanged event firing off unexpectedly - c#

I have 4 ComboBoxes arranged horizontally :
The titles are just for reference.
[Platforms] [Releases] [Release Items] [Release Item Products]
My UI model for the boxes is as follows:
At first all four ComboBoxes are disabled (IsEnabled = false)
When the page loads, an async callback gets the Platforms data and binds it to the Platforms comboBox after Enabling it, and manually add "All" as an item.
User selects a platform
If the user selects "All" , I do the following: Disable the other three comboboxes
and call the Async method to rebind data to the platforms combo box.
releasesFilterComboBox.IsEnabled = false;
releaseItemsFilterComboBox.IsEnabled = false;
releaseItemProductsFilterComboBox.IsEnabled = false;
mainClient.GetBuildsAsync(null);
If the user selects some other platform (other than 'All'), based on which platform is selected, I collect all the items that match the platform from the object in the DataContext, and set the ItemsSource of the Releases comboBox to it as follows:
BuildsListBox.ItemsSource = platformSelectedBI = from bi in buildInfos where
bi.GetBuildsResult.ReleasePlatform == selectedPlatform
select bi;
releasesFilterComboBox.IsEnabled = true;
List<String> releaseNumbers = ( from bld in buildInfos.Where(bi => bi.GetBuildsResult.ReleasePlatform == selectedPlatform)
select bld.GetBuildsResult.ReleaseNumber ).ToList();
releaseNumbers.Insert(0, "All");
releasesFilterComboBox.ItemsSource = releaseNumbers.Distinct();
The rest of the ComboBoxes follow the exact same procedure to bind data, and trigger
and actions are performed in a method which is called when the SelectionChanged events are fired.
etc etc -> same for the rest of the boxes.
My Problem is: After I've populated at least the first two ComboBoxes, when I select
the 'All' option on a PREVIOUS ComboBox, after the expected behavior (other comboboxes are disabled), when I select an option other than 'ALL', the SelectionChanged event is triggered for EVERY COMBOBOX that was filled previously! (all that were disabled). ###
Just to clarify, if it isn't yet.
I've selected a Platform, and so Releases is populated. I've then selected a Release, and so Release Items is populated. Now, when I select 'ALL' on the Platforms combobox, the Release and Release Items boxes are disabled. Then, when I select a platform other than 'ALL', the SelectionChanged event is fired, not just for Platforms, but also for Releases and ReleaseItems.
The ONLY change I'm making to the comboboxes in the second part of the event handler is SETTING THE ITEMS SOURCE like the in code shown above. Nothing more.
Why are the SelectionChanged events being fired for the other comboBoxes?
Is this a known bug in SL comboboxes? Can I prevent this from happening?
I'm sorry if the question and explanation isn't very clear. I'll try my best to clarify if you ask me.
Thanks a lot!

It all comes down to re-population of the lists. One way you could fix it would be to remove the event handlers when you select "ALL" and disable the other combo boxes. Then if you select something other than "ALL" you could set the datasources and then re-add the selection change event handler.
Another way would be to leave them all there and then in the "ALL" selection set the selected index to -1 (default) and in your event handler don't do anything if it's -1.
Just a thought.

Related

Trigger Event when listView Item is selected programmatically

I wrote an application with listViews which fill other listViews on click event. Means that when the Row in the first listView is selected it fills the second listView with the related list like dynamic dropdown lists. I am googling for hours now but I cannot find a solution.
This is what I tried but nothing will trigger the listView1_SelectedIndexChanged Event.
Thanks for your help it is very appreciated.
I tried this after researching:
listView1.Focus();
listView1.Items[index is variable].Selected = true;
listView1.Click += new EventHandler(listView1_SelectedIndexChanged);
It actually selects the row in the listView and also the row gets highlighted blue but the event is still not triggered.

list view selection mode none in windows form applications

i am working on windows form application ..i have a list view.
in the list view some time i will select some row then i will click add button .that time selected rows will add to list view.
after that i want to make my listview selection mode none so i wrote code like this
List_Item.Select = Nothing ..
but this code throwing error? how i can make my list view selection mode none?
any help is very appreciable.thanks in advance
loop every item and set the selected field to false
For Each item As ListViewItem In Me.List_Item.Items
item.Selected = false
Next

How to disable items based on condition in combo box?

Am developing a windows application in C#.
The user has to select some listed values in combo box. Those values will be added to Database. When the same user login and select the combo box, already selected values should be visible but shouldn't be get selected....
I referred various websites. All stating to change the colour of Existing values....But it is not enough. I need to disable the values... Is there any options to do it.
Note : Am populating the combo-box items from a database table.
You can set ComboBox.SelectedIndex = -1 for your desired value;
The code is not tested but something like this will help you
if (combobox.selectedIndex == (Index of your value))
{
combobox.selectedIndex = -1;
}
In this way if you try to choose that item it will set selected index to -1 and you will not able to choose that item.
The following link might be helpful for you
Create WinForms ComboBox with non-selectable items
While biding values from db set the selectable property true or false and in the selectedindexchanged event set the selectedindex of the item to -1.
Don't forget to mark it as answer if it is helpful for you.
Note: Before doing this make sure that it is required to show the items. If it is not required just filter them and bind the remaining values.

Unable to fire SelectedIndexChanged Event for a single item in a combobox

I had gone through through some of the common questions here in the forum only:
Select Index does not fire for a single item
But I have two combobox related to each other, the value selected in the A determines the value in the B and on selcting the B combobox item, data is displayed.
So I want the event, even for a single item in the B combobox.
Should I append a select item in the B Combobox so that user selects( but that is the last option).
There are other solution as well, one is to call the event of the same selected index event in the page load method.
So in this manner we can show the result of single item as well. This is not the best way but it worked out for me.

Cannot select the ComboBox item

I have two Comboboxes where the second one is dependent upon the first one.
When the SelectedIndexChanged event of the first Combobox fires then the second Combobox will be enabled.
After the event, the second Combobox is enabled but I cannot select the ComboBox item.
EDIT
I use Dev express Tools
First Combo I load in Page_Load Event
I use Server Side code:
protected void ASPxComboModule_SelectedIndexChanged(object sender, EventArgs e)
{
LoadSecondCombo();
LoadSecondCombo.Focus();
}
There is no problem in loading, but I'm unable to select 2nd combo item.
What do this do: LoadSecondCombo(); I assume it returns an instance of the control. Where does it set combo.Enabled at?
LoadSecondCombo(); LoadSecondCombo.Focus();
look like method that reference your comboBox and Load it.
When you want to focus LoadSecondCombo should ne an instance of Combo Box. I think it is not and so your combo is not selected.
Can you try going back a bit and look at the Id of combo Box (if it in a composit control like DataGrid / View you will have to do a FindControl) and then focus. I mean typing
comboBtn1.Focus();
Now if that works then you know that your control can be found. In that case mofidify the LoadSescondCombo() to return an instance of combo button if it is not doing so already.
then create a reference to that combobutton by
ComboButton cbtn = LoadSecondCombo(); and
cbtn.Focus();

Categories

Resources