Solved

combobox Winform cannot bind to valuemember

Posted on 2008-10-05
7
1,694 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
ID: 22644343
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
ID: 22644397
Remove this line
dim dssubset = new dsSubset(); //Subset Dataset

and add this one

dim dssubset = DsSTUDENTS.Clone()
0
 

Author Comment

by:dotnet0824
ID: 22644448
I tried  CLONE. it  still says it cant bind to the new display Member
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22644522
use this

Dataset  dssubset = DsSTUDENTS.Clone();

0
 

Author Comment

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

Author Comment

by:dotnet0824
ID: 22644669
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
ID: 22644692
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 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