Код | using System.Windows.Forms; namespace MainForm.Controls { public class MyGrid { public enum ColumnType { LABELCOLUMN = 0, CHECKBOX_COLUMN = 1, LINK_COLUMN = 2, COMBOBOX_COLUMN = 3 } public static DataGridViewLinkColumn getColumnLink(string name, string header, string dataPropertyName) { DataGridViewLinkColumn link = new DataGridViewLinkColumn(); link.Name = name; link.HeaderText = header; link.DataPropertyName = dataPropertyName; return link; } public static DataGridViewCheckBoxColumn getColumnCheckBox(string name, string header, string dataPropertyName) { DataGridViewCheckBoxColumn check = new DataGridViewCheckBoxColumn(); check.Name = name; check.HeaderText = header; check.DataPropertyName = dataPropertyName; return check; } public static DataGridViewComboBoxColumn getColumnComboBox(string name, string header, string dataPropertyName) { DataGridViewComboBoxColumn combo = new DataGridViewComboBoxColumn(); combo.Name = name; combo.HeaderText = header; combo.DataPropertyName = dataPropertyName; return combo; } public static DataGridViewColumn getColumn(ColumnType columnType, string name, string headerText, string dataPropertyName) { DataGridViewColumn a = null; switch (columnType) { case ColumnType.CHECKBOX_COLUMN: { a = getColumnCheckBox(name, headerText, dataPropertyName); } break; case ColumnType.LINK_COLUMN: { a = getColumnLink(name, headerText, dataPropertyName); } break; case ColumnType.COMBOBOX_COLUMN: { a = getColumnComboBox(name, headerText, dataPropertyName); } break; default: { a = new DataGridViewTextBoxColumn(); a.Name = name; a.HeaderText = headerText; a.DataPropertyName = dataPropertyName; } break; } return a; } public static DataGridViewColumn getColumn(ColumnType columnType, string name, string headerText, string dataPropertyName, int width) { DataGridViewColumn a = getColumn(columnType, name, headerText, dataPropertyName); a.Width = width; a.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; return a; } public static DataGridViewColumn getColumn(string name, string headerText) { return getColumn(ColumnType.LABELCOLUMN, name, headerText, ""); } public static DataGridViewColumn getColumn(string name, string headerText, string dataPropertyName) { return getColumn(ColumnType.LABELCOLUMN, name, headerText, dataPropertyName); } public static DataGridViewColumn getColumn(string name, string headerText, int width) { return getColumn(ColumnType.LABELCOLUMN, name, headerText, "", width); } public static DataGridViewColumn getColumn(string name, string headerText, string dataPropertyName, int width) { return getColumn(ColumnType.LABELCOLUMN, name, headerText, dataPropertyName, width); } } }
|
|