473,503 Members | 2,075 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WPF ComboBox SelectedItem binding sometimes not working properly

2 New Member
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 10582
kimic
2 New Member
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
6691
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
16176
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
3291
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
2774
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
4561
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
7490
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
3600
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
1995
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
3743
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
3012
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
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.