您的位置:程序门 -> .net技术 -> c#



checkedlistbox怎样邦定隐藏值


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


checkedlistbox怎样邦定隐藏值
发表于:2007-02-13 12:14:08 楼主
checkedlistbox1.items.add(ds.tables[ "ro "].rows[i][ "rname "],   false);   怎样邦定隐藏值,谢谢   就是rname的id
发表于:2007-02-13 12:37:121楼 得分:0
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();  
                }
发表于:2007-02-13 12:38:062楼 得分:0
可以直接绑定datarow,通过format事件.
这样selecteditem里就是datarow对象,你想要哪个字段都没有问题.
发表于:2007-02-13 12:45:233楼 得分:0
好象不能直接实现,但是你可以这样来实现
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属性了
发表于:2007-02-13 12:46:544楼 得分:0
flyaqiao(kitereport(http://www.kitesoft.cn))   的方法也不错,但是它在listbox中的显示有问题,listbox中显示的是你添加的对象的tostring()函数的结果;
发表于:2007-02-13 12:49:355楼 得分:0
flyaqiao(kitereport(http://www.kitesoft.cn))   不好意思,没有看到您的format事件代码,所以您的方法应该是可以正常显示的。
发表于:2007-02-13 13:03:126楼 得分:0
显示是没有问题,怎么能获取到,那些被选中了   private   void   checkedlistbox1_selectedindexchanged(object   sender,   eventargs   e)
                {
                        string   id   =   (checkedlistbox1.selecteditem   as   datarow)[ "id "].tostring();  
                }

选中多个,这个id怎么存,谢谢!
发表于:2007-02-13 13:30:137楼 得分:0
array吧
发表于:2007-02-13 14:30:128楼 得分:0
你可以使用format事件,这样就不会是tostring()了.
发表于:2007-02-13 17:49:569楼 得分:0
up
发表于:2007-02-13 17:58:1710楼 得分:0
该回复于2007-12-21 20:19:27被管理员或版主删除


快速检索

最新资讯
热门点击