ComBoItem.cs
2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GeneralLib
{
public class ComboItem
{
public ComboItem(int indexValue, string displayMember, string enumMember)
{
_index = indexValue;
_Name = displayMember;
_enumValue = enumMember;
}
/// <summary>
/// 索引ID
/// </summary>
private int _index = 0;
public int Index
{
get
{
return this._index;
}
set
{
this._index = value;
}
}
/// <summary>
/// 显示值
/// </summary>
private string _Name = "";
public string Name
{
get
{
return this._Name;
}
set
{
this._Name = value;
}
}
/// <summary>
/// 枚举值
/// </summary>
private string _enumValue = "";
public string EnumValue
{
get { return this._enumValue; }
set { this._enumValue = value; }
}
// ComboxItem cmitem = new ComboxItem("所有分类","-1");
//cbxSearchCodeType.Items.Add(cmitem);
//DataTable dtTypes = CodeTypeDAL.GetTypes();
//for (int i = 0; i < dtTypes.Rows.Count; i++)
//{
// ComboxItem cmitemfor = new ComboxItem(dtTypes.Rows[i["CodeTypeName"].ToString(),dtTypes.Rows[i]["ID"].ToString());
// cbxSearchCodeType.Items.Add(cmitemfor);
//}
//cbxSearchCodeType.DisplayMember = "Name";
//cbxSearchCodeType.ValueMember = "id";
//cbxSearchCodeType.SelectedIndex = 0;
}
public class ComboBoxOper
{
public static int GetIndexByValue(System.Windows.Forms.ComboBox cbo, string value)
{
try
{
int index = 0;
for (int i = 0; i < cbo.Items.Count; i++)
{
if (((ComboItem)cbo.Items[i]).EnumValue == value)
{
index = i;
break;
}
}
return index;
}
catch
{
return 0;
}
}
/// <summary>
/// 设置ComboBox的值
/// 杨斌 2014-08-05
/// </summary>
/// <param name="cbo"></param>
/// <param name="text"></param>
public static void SetComboText(System.Windows.Forms.ComboBox cbo, string text)
{
try
{
cbo.Text = text;
}
catch { }
}
}
}