Combobox databinding showing system.data.datarowview

30,801

Solution 1

This definitely happens if your cbxMetal_SelectedIndexChanged is called before cbxAlloyBinding() is called in your constructor.

For instance (see the code below), you may have other combobox bindings in constructor which may come before cbxAlloyBinding() in constructor, and those bindings are calling cbxMetal_SelectedIndexChanged.

public Constructor()
{
        InitializeComponent();

        cbxheatBinding();      //1st Three Binding Methods may be somehow related to your cbxMetal,
        dtpStartDateBinding(); //which leads them to call cbxMetal_SelectedIndexChanged method.
        dtpEndDateBinding();
        cbxAlloyBinding();
}

What I suspect is your cbxMetal.DataSource is set from some other point in your code and well before DisplayMember and ValueMember are assigned;

Just remember, System.DataRow.DataRowView will occur only if

ComboBox.SelectedValue is called before ValueMember assignment.

Solution 2

setting the DisplayMember and ValueMemeber after setting the DataSource fixed this issue for me.

cbxMetal.DataSource = dt;
cbxMetal.DisplayMember = "alloyName";
cbxMetal.ValueMember = "alloyId";
Share:
30,801
Saral Doshi
Author by

Saral Doshi

Right now I am working on windows form applications and sql server... I am here to share my knowledge as well as to solve questions and learn more things from the experienced...

Updated on November 30, 2021

Comments

  • Saral Doshi
    Saral Doshi over 2 years

    I am binding combobox with datasource, displaymember, valuemember. It is working fine in my computer but it is not working in clients pc. Following is my source code:

    cbxAlloyBinding method is called from the Constructor of the UserControl.

    private void cbxAlloyBinding()
        {
            DataTable dt = new DataTable();
            SqlDataAdapter adp = new SqlDataAdapter("SELECT alloyName,alloyId FROM alloy", con);
            adp.Fill(dt);
    
            if (dt.Rows.Count > 0)
            {
                cbxMetal.DisplayMember = "alloyName";
                cbxMetal.ValueMember = "alloyId";
                cbxMetal.DataSource = dt;
            }
            else
            {
                cbxMetal.Text = "";
            }
        }
    
        private void cbxMetal_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbxMetal.SelectedIndex != -1)
            {
                DataTable dt = new DataTable();
                tempcmd = new SqlCommand("SELECT specification,alloyCode FROM alloy where alloyId='" + cbxMetal.SelectedValue + "'", con);
                SqlDataAdapter adp = new SqlDataAdapter(tempcmd);
                adp.Fill(dt);
                if (dt.Rows.Count > 0)
                {
                    txtSpecification.Text = dt.Rows[0]["alloyCode"].ToString();
                    txtSupplyConditions.Text = dt.Rows[0]["specification"].ToString();
                    cbxheatBinding();
                }
                else
                {
                    txtSpecification.Text = "";
                }
    
            }
        }
    

    This is bothering me from last two days and i almost tried all tricks but it is still not working.

    Client's PC is using Windows 7 ultimate, sql server 2005 and .net framework 3.5.

  • Saral Doshi
    Saral Doshi over 11 years
    the a On the display it is showing system.data.datarowview and not alloynames. Client is using windows 7 ultimate. What are the other things you like to know?
  • Fredrick Gauss
    Fredrick Gauss over 11 years
    Could you please show all the code about combobox, changing properties, initializing its props? It seems that items, selecteditem edits conflict.
  • Saral Doshi
    Saral Doshi over 11 years
    I am not changing any properties or initializing any of the properties. Apart from the above code I am only using its selected value in other functions.
  • Marco Marsala
    Marco Marsala almost 9 years
    'System.Web.UI.WebControls.DropDownList' does not contain a definition for 'DisplayMember'
  • Ken
    Ken almost 8 years
    you said System.DataRow.DataRowView will occur only if ComboBox.SelectedValue is called before ValueMember assignment. I do not think that is an accurate statement as . I do not set ComboBox.SelectedValue anywhere at all and I get this condition in a particular application (geared .NET 3.5) - in other apps it works fine. I am not sure why this happens but it appears that it is related to the datatable object and .NET versions , a list<T> seems ok. - but I could be wrong.
  • Denis M. Kitchen
    Denis M. Kitchen almost 5 years
    Believe it or not, what fixed this for me was the exact OPPOSITE advise, which I found here: codeproject.com/Questions/242834/… I set the DataSource property AFTER setting the DisplayMember and ValueMember properties and my "System.Data.DataRowView" problem went away. This is such a weird bug. I also noticed, while debugging, that this problem was intermittent, making it extra hard to nail down.