I have a strange issue with a combobox. The control is bound to a collection that contains a duplicate item, albeit with different case.
They are populated in the list, via databinding, as such:
Babu
BABU
Within the application that I am creating, case is important and both items need to be displayed.
I have the selected item as BABU, yet when I open the combobox, the selectted item immediately changes to Babu without any further intervention from me. I am not handling the DropDownOpening event anywhere so there is no logic there that is causing this.
My suspicions are that it's to do with the databinding not liking what it see's as duplicate entries but I cannot be sure about this.
Has anybody experienced this before?
Open up the Designer code for that form and confirm that BABU and Babu are included in your autocomplete list for that combobox. This happened to me once where I fixed it on the form designer but it never synced up with the form designers code and it ended up containing old unwanted selections.
Also check out your autocomplete modes: http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.autocompletemode.aspx
Related
I have a project (WPF, c#) where I input some data press a button and create a "Ticket" class item and add take item to the ObservableCollection which puts them on the datagrid.
This is working fine, but I now have cause to remove certain items from the Collection where there is an error in the data. This has then led to problems to being able to iterate through the collection, as in I can not!
Reading around it seems that I am misusing the ObservableCollection by removing items from it, so my question is what should I be using in this case?
Is there any way to update a ListBox control with Dictionary binded to it without resetting its DataSource property on every dictionary change? The reason I don't like this solution is that it forces a ListBox control to jump to the first item as mentioned in other questions like this.
Here is a minimal example that reproduces this behavior -- https://bitbucket.org/ntrophimov/updating_issue (about 20 lines of code to read in the MainForm.cs file)
Is there any other solution for this problem?
Is there any dictionary implementation in which I can manipulate items (add and remove them) and these changes will be immediately represented in a ListBox control without refreshing its whole content?
The idea is:
You show your ListBox with items
User click on some item
Applications save the 'selected' item in local variable
User/App initiate ListBox update process
Update process done -> application restore (re-assign) the 'selected' item (if it still valid for current items of ListBox)
I'm writing a BHO that uses an ElementHost to host a WPF User Control. Within the user control, I have a DataGrid that binds to an Observable Collection. Everything functions fine, except that the content is not being read by screen readers (I'm using NVDA to test, but QA is using JAWS).
I'm restricted from copy & pasting code on a public forum, but I can describe the layout that I'm creating. There are two datagrid. One contains all of the items from the Observable Collection and the other is a subset of the items. Each datagrid is in a separate Tab Item of a TabControl. As I stated, there is an ObservableCollection that holds my business objects. Each object binds to a row in the datagrid. Several of the columns require that I display multiple properties from the business object, so I'm using the DataGridTemplateColumn. Within the CellStyle, I have 3 DataTemplates set up; one for edit, one for add and one for view. The view DataTemplate is exactly the same as the DataGridTemplateColumn.CellTemplate.
One of the columns holds my action buttons. One of the buttons is an edit button which simply applies the edit template to the rows cells. Outside of the datagrid, I have a button that will add a new default item to the ObservableCollection, call UpdateLayout on the datagrid, then set the DataTemplate of the new item to the add template.
There is also a button that will grab information from a remote server, convert it to business objects and add them to the Observable Collection. The datagrid loads the new information with no problems.
When I use the function to pull the objects from the database, none of the information will be read by the screen reader. If I click the edit button, everything is read as expected. After returning to the "view" DataTemplate, everything reads as expected. If I use the Add button, everything reads as expected.
To make this more complicated, if I edit an item in one tab page and get it to be read, then go to the other tab page and come back, it's no longer reading.
I have a feeling that it's related to the how binding and templates interact, but I don't know enough about either to figure out a direction to go in resolving this.
Any help would be appreciated.
EDIT: While I was creating the dummy project to show the issue, I discovered that the problem is not just limited to Template Columns. I created a business object with string properties, created an ObservableCollection with 10 objects in it and bound each property to a DataGridTextColumn, and it only reads the grid name and column index...the contents are never read.
My Search Contract populates a SearchContractResultsPages resultsList with objects, however when I try to select an item (which opens other page and passes the selection as a navigation parameter), the first item is always selected and passed as the parameter. I simply have no idea what to do to fix this, or what code needs changing, the resultsListView.SelectedItem is always the item opened, no matter what I actually select. The selection logic is carried out on the DoubleTapped event.
I don't know what code to post, so if anyone has any ideas, I will happily post I relevant parts you need to see.
Bit of a cop-out before I answer, but it depends...
If you are navigating to another page on SelectedItemChanged, the selected item should probably already be the correct one and you can use that as your navigation parameter. If this isn't working we will need to see more (come) code.
If you have an ItemClick event handler on the list view, you should use e.ClickedItem to get the correct reference back. Again, if this is what you are doing and it isn't working, we will need to see code.
Ah, I see you are switching selections on Double tapping the item. This could be the cause of your problem. Double-clicking to select is not one of the usual ways to select an item in a list. You should probably stick with the "small swipe" to select, as virtually all other apps in the ecosystem do. Not only will this let you verify what selection you have made before doing anything with it, but it will not confuse users since they're already used to the paradigm.
After typing text into a combobox during run time, how do I add it to the combobox's items property? This is in C# 2010.
The simple solution should be something like
Combobox.Items.Add(Combobox.Text);
A more elaborate solution would be perhaps to bind your Combobox.Items to some ObservableCollection in your ViewModel, and on some event (user presses Enter, etc.) the collection is updated by adding the new text (if it's still not there). This solution assumes WPF and MVVM-like approach.