Solved

vb.net combobox binding

Posted on 2009-04-01
10
1,413 Views
Last Modified: 2012-05-07
I have a winform with a datagridview and a combobox.  In the form_load event I create a dataset table and then set it to the combobox's datasource.   When I move from datagridview row to row, the combobox.text stays in synch just like it should .. the selectedvalue field is in the same datasource as the datagridview's datasource.  The problem is when I change the datasource of the combobox, the combobox displaymembers and valuemembers change as they should per the coding, but the combobox does not automatically synch to the displaymember (based on the selectedvalue matching an matching valuemember in the combobox list).

So my questions are:
a) Why does the synching work in the form_load event automatically?
b) Why does changing the datsource cause the synching to not work and how do I fix the synching?
c) Can I reference the combobox's pre-datasource change 'selectedvalue' (but the combobox.text is null because the selectedvalue cannot find a matching valuemember thus the reason for needing to update the combobox datasource)
0
Comment
Question by:kperelman
  • 5
  • 5
10 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24049165
I could not really understand what you mean. Could you please explain what you are trying to do especially in terms of functionality and in terms of coding.
0
 

Author Comment

by:kperelman
ID: 24049949
CodeCruiser:

Sorry about the ambiguity .. let me try again.  

Basically as I move from row to row in the DGV the combobox list of values needs to change (its dependent on the dgv row data).  

For example, I have a dgv with 2 columns (column1 and column2) and 3 rows.  The column1/column2  values in the rows are (1,11), (2,12) and (3,13).  The combobox selectedvalue is bound to field2 (the same field2 that the dgv uses .. same datasource).  

When I enter each dgv I need to update the combobox displaymember/valuemember list. So I load the dataset datatable with displaymember/valuemember pairs of (ItemC,13), (ItemB,12) and (ItemA,11) and update the combobox displaymember, valuemember and datasource.

I click into the dgv row 1 column1 cell.  The problem is the combobox valuemember of 11 is not binding to field2's selectedvalue of 11.  The combobox.text shows the first entry (ItemC) in the list which is not correct .. it should be ItemA.  If I manually correct the combobox selected value for row1 to ItemA and then go to row2, the combobox shows ItemB .. and then go to row3, the combobox shows ItemC .. all works again.

It's like I need to tell the combobox to refresh its bindings after I update the combobox displaymember/valuemember list?

Is this any clearer?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24050174
How do you bind the combobox? Did you use the property window to set the databindings?
0
 

Author Comment

by:kperelman
ID: 24050717
CodeCruiser:

Yes I used the property window in the IDE when I created the combobox.  I did not touch it in the code.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24050752
What property you have bound and how? May be doing it in the code would help.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:kperelman
ID: 24051246
CodeCruiser::

I am not sure how to do this in code?

a) Should I use combobox.databindings.add()
b) If yes, should I do a combobox.databindings.remove() or a combobox.databindings.clear()
c) Where should I place (a) .. before or after the setting the combobox.datasource?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24051547
Did you say that you want the combobox to change when you click on a different row in the datagrid?
0
 

Author Comment

by:kperelman
ID: 24052614
CodeCruiser:

Yes
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 24057877
I think you would load the combobox once and then write code against the selection change event of the grid to manually select a different value in the combobox instead of binding it to the grid.
0
 

Author Closing Comment

by:kperelman
ID: 31597476
Thanks for your help.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now