Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Binding to Combo Box Problem

Posted on 2010-09-05
2
Medium Priority
?
362 Views
Last Modified: 2013-12-17
I have church membership data which is organized by family (FamilyData), member (MbrData) and Attendance. Attendance is tied to member and member to family. I want to be able to move a family member from one family to another (necessary if children marry to form a new family or if an adult child moves out and creates a new family). The idea was to chose the family and member from one pair of bound combo boxes (losing family) and independently choose a gaining family. Then simply change the member's FamilyID from the losing family to the gaining family. (This is probably naive and bound to fail -- suggestions on a better way would be appreciated.)

Hence, I have one dataset that I want to bind the two family comboboxes to the same table but have them work independently. I am mimicking
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_22708357.html?sfQueryTermInfo=1+10+30+bind+combobox 
but not getting the correct response. The second box acts as if it is not bound at all. The FamilyDataBindingSource is the original binding source for the FamilyData table in the CATDataset.

I would appreciate suggestions and/or corrections in the following code.
'The following was generated by the designer -- the first box.
        'cboLosingFamily
        '
        Me.cboLosingFamily.DataSource = Me.FamilyDataBindingSource
        Me.cboLosingFamily.DisplayMember = "FamilyName"
        Me.cboLosingFamily.FormattingEnabled = True
        Me.cboLosingFamily.Location = New System.Drawing.Point(137, 74)
        Me.cboLosingFamily.Name = "cboLosingFamily"
        Me.cboLosingFamily.Size = New System.Drawing.Size(110, 21)
        Me.cboLosingFamily.TabIndex = 6
        Me.cboLosingFamily.ValueMember = "FamilyID"



'The following was coded by me -- the second box.
        With cboGainingFamily
            .DataSource = New BindingSource(CATDataSet.FamilyData, vbNull)
            .DisplayMember = CATDataSet.FamilyData.FamilyNameColumn.ColumnName
            .ValueMember = CATDataSet.FamilyData.FamilyIDColumn.ColumnName
        End With

Open in new window

0
Comment
Question by:rkulp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Expert Comment

by:pnedic
ID: 33609824
I'm not sure will it help you but you ca try this.
Try to use DataView as datasource for your combo boxes (both of them). What I'm doing is this (sorry in C#). See bellow the code.
Also you should take care to do following:
when you select someValue in cboLosingFamily combo, to exclude that value in cboGainingFamily, or to set some other kind of this prohibition.
Hope this will give you some help or some additional idea.
Regards

DataView myDV1 = new DataView();
DataView myDV2 = new DataView();
myDV1 = myDataTable.DefaultView;
myDV2 = myDataTable.DefaultView;

cmb1.BindingContext = new BindingContext();  //as MUST
cmb1.ValueMember = "myValueMemb";    //first data from myDataTable
cmb1.DisplayMember = "myDisplMemb";  //second data from myDataTable
cmb1.DataSource = myDV1;

cmb2.BindingContext = new BindingContext();  //as MUST
cmb2.ValueMember = "myValueMemb";    //first data from myDataTable
cmb2.DisplayMember = "myDisplMemb";  //second data from myDataTable
cmb2.DataSource = myDV2;

Open in new window

0
 
LVL 1

Accepted Solution

by:
rkulp earned 0 total points
ID: 33610779
pnedic,

Thanks for your response. This did not work but I may have done something wrong in the translation. However, I did stumble on the solution. In the designer, I looked at "Other Data Sources" and expanded it until finding the data table. After selecting that the display member and value member worked as usual and all was well. This is what I should have done in the first place.
0

Featured Post

Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

704 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