日期:2014-05-17  浏览次数:20819 次

可以依次给comboBox的items赋valuemember属性赋值吗?
我从数据库取出两列数据,一列做items的text,另一列经过判断后,把某个小集合内的items的valuemember赋相同的值,我是下面这样做的,没有实现,请大家帮忙啊!

C# code
myConn = new SqlConnection(myConnStr);
            myConn.Open();
            String myCmdStr_MemberName = "Select memberID,classID From tbMember Order By memberID";
            SqlCommand myCMD_MemberName = new SqlCommand(myCmdStr_MemberName,myConn);
            SqlDataReader myDR_MemberName = myCMD_MemberName.ExecuteReader();
            while (myDR_MemberName.Read())
            {                
                 if (myDR_MemberName.GetString(1) == "JXJX" || myDR_MemberName.GetString(1) == "WFWF")
                {
                    this.comB_MateName.Items.Add(myDR_MemberName.GetString(0));
                    this.comB_MateName.ValueMember = "GD";
                }
                else if (myDR_MemberName.GetString(1) == "ZHZH")
                {
                    this.comB_MateName.Items.Add(myDR_MemberName.GetString(0));
                    this.comB_MateName.ValueMember = "BKBK";
                }
                else
                {
                    this.comB_MateName.Items.Add(myDR_MemberName.GetString(0));
                    this.comB_MateName.ValueMember = "JDJD";
                }
            }
            myDR_MemberName.Close();
            myConn.Close();


------解决方案--------------------
valuemember是说的作为值的字段(属性)名,而不是值本身。你用错了。