您的位置:程序门 -> .net技术 -> 组件/控件开发



有关组合控件的问题,请高手赐教


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


有关组合控件的问题,请高手赐教[无满意答案结贴,结贴人:jxzhaogang]
发表于:2007-10-15 08:46:25 楼主
1.   我定义了一个自定义组件如下:  
using   system;  
using   system.collections.generic;  
using   system.componentmodel;  
using   system.drawing;  
using   system.data;  
using   system.text;  
using   system.windows.forms;  
using   system.collections;  

namespace   jxerpcomponent  
{  
        public   partial   class   jxlabelcombobox   :   usercontrol  
        {  
                public   jxlabelcombobox()  
                {  
                        initializecomponent();  
                        this.databindings.collectionchanged+=new   collectionchangeeventhandler                       (databindings_collectionchanged);  
                }  

                void   databindings_collectionchanged(object   sender,   collectionchangeeventargs   e)  
                {  
                        if   ((e.action   ==   collectionchangeaction.add)   &&   (e.element   !=   null)   &&   ((e.element   as   binding).propertyname   ==   "selectvalue"))   //text  
                        {  
                                binding   bd   =   new   binding("selectedvalue",   (e.element   as   binding).datasource,   (e.element   as   binding).bindingmemberinfo.bindingfield);  
                                this.combobox.databindings.add(bd);  
                        }  
                }  
                private   object   selectvalue;  
                public   object   selectvalue  
                {  
                        get   {  
                                this.selectvalue   =   this.combobox.selectedvalue;  
                                return   this.selectvalue;  
                        }  
                        set  
                        {  
                                        this.selectvalue   =   value;  
                                        this.combobox.selectedvalue   =   value;  
                                        this.invalidate();  
                        }  
                }  
}  
做了一个测试范例:  
using   system;  
using   system.collections.generic;  
using   system.componentmodel;  
using   system.data;  
using   system.drawing;  
using   system.text;  
using   system.windows.forms;  
using   system.collections;  

namespace   componenttest  
{  
        public   partial   class   frmjxcontrol   :   form  
        {  
                public   frmjxcontrol()  
                {  
                        initializecomponent();  
                }  

                private   void   frmjxcontrol_load(object   sender,   eventargs   e)  
                {  
                        arraylist   al   =   new   arraylist();  
                        al.add(new   a("a1",1));  
                        al.add(new   a("a2",2));  
                        al.add(new   a("a3",   3));  

                        arraylist   b1   =   new   arraylist();  
                        b1.add(new   b("b1",1));  
                        b1.add(new   b("b2",   2));  

                        this.datagridview1.datasource   =   al;  

                        this.combobox1.datasource   =   b1;  
                        this.combobox1.displaymember   =   "b1";  
                        this.combobox1.valuemember   =   "c2";  
                        this.combobox1.databindings.add("selectedvalue",   al,   "c2");  

                        this.jxlabelcombobox2.datasource   =   b1;  
                        this.jxlabelcombobox2.displaymember   =   "b1";  
                        this.jxlabelcombobox2.valuemember   =   "c2";  
                        this.jxlabelcombobox2.datapropertyname   =   "c2";  
                        this.jxlabelcombobox2.databindings.add("selectvalue",   al,   "c2");  
                        this.jxlabelcombobox2.enabled   =   true;  
                }  
        }  
        public   class   a  
        {  
                public   a(string   vc1,   int   vc2)  
                {  
                        c1   =   vc1;  
                        c2   =   vc2;  
                }  

                private   string   c1;  
                public   string   c1  
                {  
                        get   {   return   c1;   }  
                        set   {   c1   =   value;   }  
                }  
                private   int   c2;  
                public   int   c2  
                {  
                        get   {   return   c2;   }  
                        set   {   c2   =   value;   }  
                }  

        }  
        public   class   b  
        {  
                public   b(string   vb1,   int   vc2)  
                {  
                        b1   =   vb1;  
                        c2   =   vc2;  
                }  
                private   string   b1;  
                public   string   b1  
                {  
                        get   {   return   b1;   }  
                        set   {   b1   =   value;   }  
                }  
                private   int   c2;  
                public   int   c2  
                {  
                        get   {   return   c2;   }  
                        set   {   c2   =   value;   }  
                }  

        }  
}  
问题:  
      每次从grid的第三行跳到第二行时都回报错。  
      请高手指教。  
发表于:2007-10-17 11:13:251楼 得分:0
报什么错啊,在表格内移动记录第三行跳到第二行吗?
发表于:2007-10-17 13:40:372楼 得分:0
up
发表于:2007-10-18 18:19:193楼 得分:0
對,移動到第三行以後再到第二行的時候就會報錯。並且數據都不会顯示出來。


快速检索

最新资讯
热门点击