该程序主要参考codeProject上的一个程序,链接已失去,不过要想其致敬!

    

      默认的combobox是不提供多列显示的,所以这里要用绘制的方法显示该功能,主要是重写combobox。其中combobox有个属性DrawMode,需将其设为DrawMode.OwnerDrawVariable,原因如下:从MSDN摘录.

Normal 控件中的所有元素都由操作系统绘制,并且元素大小都相等。 
OwnerDrawFixed 控件中的所有元素都是手动绘制的,并且元素大小都相等。 
OwnerDrawVariable 控件中的所有元素都由手动绘制,元素大小可能不相等。 

      具体步骤如下:实例以datatable为数据源,数据源也可以是arraylist或通过add()方法添加

         int columnPadding = 5;
        private float[] columnWidths = new float[0];  //项宽度
        private String[] columnNames = new String[0]; //项名称
        private int valueMemberColumnIndex = 0;       //valueMember属性列所在的索引

        }

 

 

绘制字符串所使用的两个方法:

 

        }

 

 界面层绑定数据源:

 

 

combobox控件实现多列显示            DataTable dataTable = new DataTable("Employees");
combobox控件实现多列显示
combobox控件实现多列显示            dataTable.Columns.Add(
"Employee ID"typeof(String));
combobox控件实现多列显示            dataTable.Columns.Add(
"Name"typeof(String));
combobox控件实现多列显示            dataTable.Columns.Add(
"Country"typeof(String));
);

      有需要源码的朋友同样可以到我的群中下载.

 

相关文章:

  • 2022-02-07
  • 2022-12-23
  • 2022-02-12
  • 2021-12-15
  • 2022-03-01
  • 2021-12-20
  • 2022-12-23
猜你喜欢
  • 2021-07-21
  • 2022-03-07
  • 2022-01-02
  • 2021-11-11
  • 2021-11-27
相关资源
相似解决方案