473,289 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

WPF ComboBox SelectedItem binding sometimes not working properly

2
Hello, i am using WPF combobox in my application.
1) I create and add a combobox to a visual container (usualy Grid) by runtime or it is defined in the XAML page
2) I assign combobox source to the new xmldocument, this loads the content and then document xml data populate the combo items
3) When page init is finished i load page data to setup the form, I set loaded comboboxes to the selecteditems
4) page.show();

this seems to work, but there is like 10% chance that the combobox is loaded, but the selecteditem is blank although the itemsource was populated and selecteditem was set to proper id.
When i trace the code in debug it works on 100% but when i run it without debug it occasionaly forgets to setup the combobox selection.

I have found that this is some sort of bug of WPF combobox, and its possible to "correct" it in the XAML by swaping:
Expand|Select|Wrap|Line Numbers
  1. <ComboBox ItemsSource="{Binding Countries, Mode=OneWay}" SelectedItem="{Binding SelectedCountry}" DisplayMemberPath="Name" > </ComboBox>
  2.  
  3. to:
  4.  
  5. <ComboBox SelectedItem="{Binding SelectedCountry}" ItemsSource="{Binding Countries, Mode=OneWay}" DisplayMemberPath="Name" > </ComboBox>
  6.  
but because i setup and load data in runtime, i do the bindings in the runtime without XAML. Is there any workarround for this?

is there any event or trigger that can help to find out, if the combobox has realy finished loading? Also some switch that will forbid combobox to load itemsource in separate thread would be good, as it is unstable in current combobox version.I am using .Net 3.5 SP1

I have tried also this:

SelectedValueId is String property that buffers the id of target record ...
Expand|Select|Wrap|Line Numbers
  1. combo1.Loaded += delegate { if (SelectedValueId != null) SetSelected(); };
  2.  
but its still buggy, sometimes the combobox doesnt select choosen item properly although it is supposed to do it correctly from the inputs and in debug
May 12 '10 #1
1 10545
kimic
2
So probably i have found the cause of the problem, the combobox was correct, but the source was xmlprovider, which was running asynchronous by the default.

this code fixed it:



xmlsourcedata.IsAsynchronous=false;

xmlsourcedata.IsInitialLoadEnabled = true;

xmlsourcedata.Document.InnerXml = trn2.GetRootNode().OuterXml;

xmlsourcedata.Refresh();



...

Combobox binding code

..

Combobox SetSelectedId code
May 12 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Kamyk | last post by:
Hello all! Could you tell me where is the error on the below code, because the script is sometimes working correctly and sometimes is not working correctly. I want my new window with picture...
3
by: ScottO | last post by:
I would like the user to have to select something in a System.Windows.Forms.ComboBox. private void MyForm_Load(object sender, System.EventArgs e) { ... comboBox.DataSource = data;...
1
by: Roberto Castro | last post by:
I have some problems with the way I am showing the BLOB fields in the Image web controls. It does work on my localhost though sometimes I need to hit Refresh for the images to load properly....
5
by: Nita Raju | last post by:
Hi, I have to validate a textbox for date without using the validation controls. So i had to use IsDate(). It's not working properly when i give "11//2004". When i enter the above date it...
12
kamill
by: kamill | last post by:
I have done a logout page for logout from admin section and provides a link to logout from admin section.Whenever i clicked on logout link it redirected to index.php of admin section......BUT when i...
3
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
5
by: damezumari | last post by:
When a user logs in to my site http://iwantyourquestion.com I set $_SESSION to true if his username and password are OK. When he calls a page I check if $_SESSION is true. If it not I ask him to...
3
by: rajasree | last post by:
Hi all, am doing a project in PHP. my javascript code is working properly in ie. But its not working in firefox. Please help me my code is as follows; <script language="javascript"...
4
by: zairali | last post by:
Hi, I am trying to fix a webpage ( http://www.d.umn.edu/itss/labs/maps/ ) which uses some html (or xml also?) to show pop ups when you rollover the numbers on a map of the building. They work fine...
1
by: Jiwei06xie | last post by:
Hi, I have a main form with 3 subforms and some combo boxes. It is working fine as an independent form. However, when I draged into a tabcontrol page, two off the combo boxes stopped working...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.