-
Notifications
You must be signed in to change notification settings - Fork 18
Home
Radu Martin edited this page Apr 15, 2017
·
18 revisions
These extenders simplify the work with data-bound in WinForms.
gridView.GenerateColumns(DataSource,
new ColumnDataDescriptor("Header1", "Column1Name"),
new ColumnDataDescriptor("Header2", "Column2Name"),
new ColumnDataDescriptor("Header3", "Column3Name", FillWeight: 100));
layoutPanel.GenerateGroups(DataSource,
new GroupDataDescriptor("GroupName1",
new FieldDataDescriptor("Header1", "Column1Name"),
new FieldDataDescriptor("Header2", "Column2Name")),
new GroupDataDescriptor("GroupName2",
new FieldDataDescriptor("Header3", "Column3Name")));
layoutPanel.GenerateFields(DataSource,
new FieldDataDescriptor("Header1", "Column1Name"),
new FieldDataDescriptor("Header2", "Column2Name"),
new FieldDataDescriptor("Header3", "Column3Name"));
var Database = ...; // create typed DataSet
// praparing Grids
var tbl1 = this.Database.Departments;
var departmentsBindingSource = new System.Windows.Forms.BindingSource(this.components);
departmentsBindingSource.DataMember = Database.Departments.TableName;
departmentsBindingSource.DataSource = Database;
this.departmentsGridView.GenerateColumns(departmentsBindingSource,
new ColumnDataDescriptor("Department", tbl1.DepartmentNameColumn),
new ColumnDataDescriptor("Is closed?", tbl1.IsClosedColumn),
new ColumnDataDescriptor("Group", tbl1.CompanyGroupColumn),
new ColumnDataDescriptor("Remarks", tbl1.RemarksColumn, FillWeight: 100));
this.departmentsGridView.PrepareStyleForEditingData();
this.departmentsGridView.AddDataRowStateDrawingInRowHeaders();
var tbl2 = this.Database.Employees;
var employeesBindingSource = new System.Windows.Forms.BindingSource(this.components);
employeesBindingSource.DataMember = Database.Employees.TableName;
employeesBindingSource.DataSource = Database;
var _salaryGroups = daoDataSet.CreateSalaryGroupsLookupTable();
this.employeesGridView.GenerateColumns(employeesBindingSource,
new ColumnDataDescriptor("Employee", tbl2.EmployeeNameColumn, FillWeight: 100),
new ColumnDataDescriptor("Department", tbl2.DepartmentIDColumn, DataSource: tbl1, ValueMember: tbl1.DepartmentIDColumn.ColumnName, DisplayMember: tbl1.DepartmentNameColumn.ColumnName),
new ColumnDataDescriptor("Phone", tbl2.PhoneNumberColumn, Mode: ColumnEditorMode.TextBox, FormatValueMethod: new FormatValueDelegate(this.FormatPhoneValue)),
new ColumnDataDescriptor("Date of birth", tbl2.DateBirthColumn, Style: EditorDataStyle.Date),
new ColumnDataDescriptor("Group of Salary", tbl2.SalaryGroupColumn, DataSource: _salaryGroups, ValueMember: _salaryGroups.Columns[0].ColumnName, DisplayMember: _salaryGroups.Columns[1].ColumnName),
new ColumnDataDescriptor("Salary", tbl2.SalaryColumn, Style: EditorDataStyle.Money));
this.employeesGridView.PrepareStyleForEditingData();
this.employeesGridView.AddDataRowStateDrawingInRowHeaders();
// preparing Panels
this.departmentsPanel.GenerateGroups(this.toolTip, departmentsBindingSource,
new GroupDataDescriptor("Identifications",
new FieldDataDescriptor("ID", tbl1.DepartmentIDColumn, IsReadOnly: true),
new FieldDataDescriptor("Department", tbl1.DepartmentNameColumn)),
new GroupDataDescriptor("Overview", (int)DataDescriptorSizeWidth.Smaller,
new FieldDataDescriptor("Is closed", tbl1.IsClosedColumn),
new FieldDataDescriptor("Group", tbl1.CompanyGroupColumn, DataSource: new string[] { "AM", "HR", "MM", "MN", "KT", "SM" })),
new GroupDataDescriptor("Additions",
new FieldDataDescriptor("Remarks", tbl1.RemarksColumn)));
this.employeesPanel.GenerateGroups(this.toolTip, employeesBindingSource,
new GroupDataDescriptor("Identifications",
new FieldDataDescriptor("ID", tbl2.EmployeeIDColumn, IsReadOnly: true),
new FieldDataDescriptor("Employee", tbl2.EmployeeNameColumn),
new FieldDataDescriptor("Department", tbl2.DepartmentIDColumn, DataSource: tbl1, ValueMember: tbl1.DepartmentIDColumn.ColumnName, DisplayMember: tbl1.DepartmentNameColumn.ColumnName)),
new GroupDataDescriptor("Overview", (int)DataDescriptorSizeWidth.Small + (int)DataDescriptorSizeWidth.Smaller,
new FieldDataDescriptor("Phone", tbl2.PhoneNumberColumn, Mode: FieldEditorMode.TextBox, FormatValueMethod: new FormatValueDelegate(this.FormatPhoneValue)),
new FieldDataDescriptor("Date of birth", tbl2.DateBirthColumn, Style: EditorDataStyle.Date)),
new GroupDataDescriptor("Salary", (int)DataDescriptorSizeWidth.Small,
new FieldDataDescriptor("Group", tbl2.SalaryGroupColumn, Mode: FieldEditorMode.ListBox, DataSource: _salaryGroups, ValueMember: _salaryGroups.Columns[0].ColumnName, DisplayMember: _salaryGroups.Columns[1].ColumnName),
new FieldDataDescriptor("Salary", tbl2.SalaryColumn, Style: EditorDataStyle.Money)));
DataViewExtenders use special things that were introduced in .NET Framework 4.0:
- Extension Methods (introduced in .NET Framework 3.5)
- String.IsNullOrWhiteSpace method
- Tuple Class
Extenders:
DataGridView
DataGridViewColumn
FlowLayoutPanel
TableLayoutPanel
Features:
SelectItemForm
Settings
Components:
BitMaskCheckedListBox
HeaderTableLayoutPanel
SelectItemForm