1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows;
6 using System.Windows.Forms;
7 using System.Data;
8
9 namespace Geovin.Du.FormOperatingBase
10 {
11 /// <summary>
12 /// ComboBox 綁定值或索引值
13 /// 20110909
14 /// 塗聚文 締友計算機信息技術有限公司
15 /// </summary>
16 public class SetComBoxDataBinding
17 {
18 public enum strSort
19 {
20 Desc,
21 Asc
22 };
23 /// <summary>
24 /// ComboBox 綁定值
25 /// </summary>
26 /// <param name="sComboBox">combox 控件名称</param>
27 /// <param name="sFieldName">显示的名称</param>
28 /// <param name="sFieldNameValue">所显示的ID或值</param>
29 /// <param name="dt"></param>
30 public static void setComboList(ComboBox sComboBox, string sFieldName, string sFieldNameValue,DataTable dt)
31 {
32 //原用的
33 sComboBox.DataSource = dt.DefaultView;//
34 sComboBox.DisplayMember = sFieldName;//显示字段
35 sComboBox.ValueMember = sFieldNameValue;//字段值,如ID
36 //dt.Dispose();
37 //dt.Clear();
38
39 }
40 /// <summary>
41 /// ComboBox 綁定值 並索引
42 /// 20120905
43 /// 塗聚文 締友計算機信息技術有限公司
44 /// </summary>
45 /// <param name="sComboBox">ComboBox</param>
46 /// <param name="sFieldName">显示的名称</param>
47 /// <param name="sFieldNameValue">屬性值</param>
48 /// <param name="dt">索引的值</param>
49 /// <param name="strSort"></param>
50 public static void setComboSortList(ComboBox sComboBox, string sFieldName, string sFieldNameValue, DataTable dt,strSort sort)
51 {
52
53 //原用的
54 switch (sort)
55 {
56 case strSort.Asc:
57 dt.DefaultView.Sort = sFieldName + " Asc";
58 break;
59 case strSort.Desc:
60 dt.DefaultView.Sort = sFieldName + " Desc";
61 break;
62
63 }
64
65 sComboBox.DataSource = dt.DefaultView;//
66 sComboBox.DisplayMember = sFieldName;//显示字段
67 sComboBox.ValueMember = sFieldNameValue;//字段值,如ID
68 //dt.Dispose();
69 //dt.Clear();
70
71 }
72 /// <summary>
73 /// State, ZipCode DESC
74 /// </summary>
75 /// <param name="dt">DataTable</param>
76 /// <param name="str">State, ZipCode DESC</param>
77 private void SortByTwoColumns(DataTable dt,string str)
78 {
79
80 DataView view = dt.DefaultView;
81 view.Sort = str;
82 }
83 }
84 }
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)成功.---Geovin Du(涂聚文)