Solved

combobox Winform cannot bind to valuemember

Posted on 2008-10-05
7
1,704 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
[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
  • 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 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