-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowsFormsUtility.cs
More file actions
52 lines (47 loc) · 1.71 KB
/
WindowsFormsUtility.cs
File metadata and controls
52 lines (47 loc) · 1.71 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
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CPUWindowsFormFramework
{
public class WindowsFormsUtility
{
public static void SetListBinding(ComboBox lst, DataTable sourcedt, DataTable targetdt, string tablename)
{
lst.DataSource = sourcedt;
lst.ValueMember = tablename + "Id";
lst.DisplayMember = lst.Name.Substring(3);
lst.DataBindings.Add("SelectedValue", targetdt, lst.ValueMember, false, DataSourceUpdateMode.OnPropertyChanged);
}
public static void SetControlBinding(Control ctrl, DataTable dt)
{
string propertyname = "";
string controlname = ctrl.Name.ToLower();
string columnname = controlname.Substring(3);
string controltype = controlname.Substring(0, 3);
switch (controltype)
{
case "txt":
case "lbl":
propertyname = "Text";
break;
case "dtp":
propertyname = "Value";
break;
}
if (propertyname != "" && columnname != "")
{
ctrl.DataBindings.Add(propertyname, dt, columnname, true, DataSourceUpdateMode.OnPropertyChanged);
}
}
public static void FormatGridForSearchResults(DataGridView grid)
{
grid.AllowUserToAddRows = false;
grid.ReadOnly = true;
grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
grid.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
}
}