checkedListBox1.Items.Add(ds.Tables["Ro"].Rows[i]["RName"], false); 怎样邦定隐藏值,谢谢 就是RName的ID

解决方案 »

  1.   

    checkedListBox1.Items.Add(ds.Tables["Ro"].Rows[i], false); 
     private void checkedListBox1_Format(object sender, ListControlConvertEventArgs e)
            {
                e.Value = (e.ListItem as DataRow)["RName"].ToString(); 
            }        private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                string id = (checkedListBox1.SelectedItem as DataRow)["Id"].ToString(); 
            }
      

  2.   

    可以直接绑定DataRow,通过Format事件.
    这样SelectedItem里就是DataRow对象,你想要哪个字段都没有问题.
      

  3.   

    好象不能直接实现,但是你可以这样来实现
    public clsItemEntity
    {
       public string Name;
       public string id;
       public clsItemEntity(string strName,int intID)
       {
          this.Name = strName;
          this.id = intID;
       }
       public override string toString()
       {
          return this.Name;
       }
    }
    在checkedListBox填充代码中
    checkedListBox1.Items.Add(new("Name1",1),false) ;checkedListBox1.Items.Add(new("Name2",2),false) ;
    checkedListBox1.Items.Add(new("Name3",3),false) ;
    要取数据时使用checkedListBox1.CheckedItems[]来引用被Checked的对象
    然后将其强制转型为clsItemEntity就可以使用它的id属性了
      

  4.   

    flyaqiao(KiteReport(http://www.kitesoft.cn)) 的方法也不错,但是它在listBox中的显示有问题,ListBox中显示的是你添加的对象的ToString()函数的结果;
      

  5.   

    flyaqiao(KiteReport(http://www.kitesoft.cn)) 不好意思,没有看到您的Format事件代码,所以您的方法应该是可以正常显示的。
      

  6.   

    显示是没有问题,怎么能获取到,那些被选中了 private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                string id = (checkedListBox1.SelectedItem as DataRow)["Id"].ToString(); 
            }选中多个,这个id怎么存,谢谢!
      

  7.   

    你可以使用Format事件,这样就不会是ToString()了.