Solved

combobox Winform cannot bind to valuemember

Posted on 2008-10-05
7
1,678 Views
Last Modified: 2013-12-17
Hi I have a Dataset of studentData

I make a subset of Active Students into a different Dataset... Original dataset bound , I have no problems

I try binding this Dataset to the combo. It fails to bind.  

If I bind the Original Dataset(dsStudents)  to the combo its fine. It only fails if i bind it to subset At valueMember property

  dim dssubset = new dsSubset(); //Subset Dataset

  DataRow[] rows = DsSTUDENTS.Tables[0].Select("Active=1");  //Original Dataset

   dssubset = MakeDataSet(rows); //to make subset of original dataset
 


 public DataSet MakeDataSet(DataRow[] drRows)
        {
            DataTable dt = new DataTable();
            foreach (DataRow dr in drRows)
            {
                dt.ImportRow(dr);
            }
            DataSet dsNew = new DataSet();
            dsNew.Tables.Add(dt);
            return dsNew;

        }


                  ////// THIS WORKS FINE ////////////////////
                    this.COMBOBOX.DataSource = dsStudents.Tables[0];
                    this.ComboBox.DisplayMember = "Name";
                    this.combobox.ValueMember = "Student_ID";  


//////////////////////////FAILS HERE SUBSET OF ORIGINAL DATASET
                 
                    this.COMBOBOX.DataSource = dssubset.Tables[0];
                    this.ComboBox.DisplayMember = "Name";
                    this.combobox.ValueMember = "Student_ID"; //FAILS HERE SAYING CANNOT BIND TO DATAMEMBER
0
Comment
Question by:dotnet0824
  • 4
  • 2
7 Comments
 
LVL 5

Accepted Solution

by:
gemailj earned 500 total points
Comment Utility
instead of using .Select()
try use DsSTUDENTS.Tables[0].DefaultView.RowFilter  Property


try this code
DataView dvActive = DsSTUDENTS.Tables[0].DefaultView;

dvActive.RowFilter = "Active=1";
 
 

this.ComboBox.DataSource = dvActive;

this.ComboBox.DisplayMember = "Name";

this.combobox.ValueMember = "Student_ID";

Open in new window

0
 
LVL 16

Expert Comment

by:Gyanendra Singh
Comment Utility
Remove this line
dim dssubset = new dsSubset(); //Subset Dataset

and add this one

dim dssubset = DsSTUDENTS.Clone()
0
 

Author Comment

by:dotnet0824
Comment Utility
I tried  CLONE. it  still says it cant bind to the new display Member
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 16

Expert Comment

by:Gyanendra Singh
Comment Utility
use this

Dataset  dssubset = DsSTUDENTS.Clone();

0
 

Author Comment

by:dotnet0824
Comment Utility
Yes bond. I used that then copied all rows which r active to the dsSubSet and tried to bind
0
 

Author Comment

by:dotnet0824
Comment Utility
i tried this it works (Any idea whats wrong Bond with that)

DataView dvActive = DsSTUDENTS.Tables[0].DefaultView;
dvActive.RowFilter = "Active=1";
 
 
this.ComboBox.DataSource = dvActive;
this.ComboBox.DisplayMember = "Name";
this.combobox.ValueMember = "Student_ID";
0
 

Author Comment

by:dotnet0824
Comment Utility
Hi,
How did i get the row Values In the selectedchangeEvent of combo after I bind it to the dataView

DataView dvActive = DsSTUDENTS.Tables[0].DefaultView;
dvActive.RowFilter = "Active=1";
 this.ComboBox.DataSource = dvActive;
this.ComboBox.DisplayMember = "Name";
this.combobox.ValueMember = "Student_ID";
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
crm development 2 35
Problem to open Excel file 15 38
ConsoleSql 1 14
Create a form which is copy of a form in vb.net 2 17
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

10 Experts available now in Live!

Get 1:1 Help Now