// Set column styles
// Set datagrid ColumnStyle for Car field
DataGridTextBoxColumn colCar = new DataGridTextBoxColumn();
colCar.MappingName = "Car";
colCar.HeaderText = "Car Name";
colCar.Width = 130;
colCar.NullText = String.Empty;
colCar.ReadOnly = true;
TblStyle.GridColumnStyles.Add(colCar);
// Set datagrid ComboBox ColumnStyle for PubID field
DataTable tblCompanies = ds.Tables["Companies"];
TblStyle.GridColumnStyles.Add(new DataGridComboBoxColumn(ref tblCompanies, 1, 0, true, false, true));
// Datagrid ComboBox DisplayMember field has order number 1. Name of this column is "Name"
// Datagrid ComboBox ValueMember field has order number 0. Name of this column is "PubID"
TblStyle.GridColumnStyles[1].MappingName = "PubID";
TblStyle.GridColumnStyles[1].HeaderText = "Company ID";
TblStyle.GridColumnStyles[1].Width = 200;
TblStyle.GridColumnStyles[1].NullText = String.Empty;
// Set datagrid combobox ColumnStyle for State field
DataTable tblStates = ds.Tables["States"];
TblStyle.GridColumnStyles.Add(new DataGridComboBoxColumn(ref tblStates, 0, 0, true, false, false));
// Datagrid ComboBox DisplayMember field has order number 0. Name of this column is "State"
// Datagrid ComboBox ValueMember field has order number 0. It is the same column like for DisplayMember
TblStyle.GridColumnStyles[2].MappingName = "State";
TblStyle.GridColumnStyles[2].HeaderText = "State";
TblStyle.GridColumnStyles[2].Width = 45;
TblStyle.GridColumnStyles[2].NullText = String.Empty;
// Set datagrid XP Style Button ColumnStyle for City field
TblStyle.GridColumnStyles.Add(new DataGridXPButtonColumn());
// Also you may set datagrid Button ColumnStyle for City
// field without XP Button Style as the following:
// .Add(New DataGridButtonColumn())
TblStyle.GridColumnStyles[3].MappingName = "City";
TblStyle.GridColumnStyles[3].HeaderText = "City";
TblStyle.GridColumnStyles[3].Width = 60;
TblStyle.GridColumnStyles[3].NullText = String.Empty;
// Set datagrid Memo ColumnStyle for Comments field
TblStyle.GridColumnStyles.Add(new DataGridMemoColumn("Car description"));
TblStyle.GridColumnStyles[4].MappingName = "Comments";
TblStyle.GridColumnStyles[4].HeaderText = "Comments";
TblStyle.GridColumnStyles[4].Width = 60;
|
// Set column styles
// Set datagrid ColumnStyle for Car field
DataGridTextBoxColumn colCar = new DataGridTextBoxColumn();
colCar.MappingName = "Car";
colCar.HeaderText = "Car Name";
colCar.Width = 130;
colCar.NullText = String.Empty;
colCar.ReadOnly = true;
TblStyle.GridColumnStyles.Add(colCar);
// Set datagrid ComboBox ColumnStyle for PubID field
DataTable tblCompanies = ds.Tables["Companies"];
TblStyle.GridColumnStyles.Add(new DataGridComboBoxColumn(ref tblCompanies, 1, 0, true, false, true));
// Datagrid ComboBox DisplayMember field has order number 1. Name of this column is "Name"
// Datagrid ComboBox ValueMember field has order number 0. Name of this column is "PubID"
TblStyle.GridColumnStyles[1].MappingName = "PubID";
TblStyle.GridColumnStyles[1].HeaderText = "Company ID";
TblStyle.GridColumnStyles[1].Width = 200;
TblStyle.GridColumnStyles[1].NullText = String.Empty;
......................
// Set datagrid XP Style Button ColumnStyle for City field
TblStyle.GridColumnStyles.Add(new
DataGridXPButtonColumn(SystemColors.ControlText, SystemColors.Control));
// Also you may set datagrid Button ColumnStyle for City
// field without XP Button Style as the following:
// .Add(New DataGridButtonColumn())
TblStyle.GridColumnStyles[3].MappingName = "City";
TblStyle.GridColumnStyles[3].HeaderText = "City";
TblStyle.GridColumnStyles[3].Width = 60;
TblStyle.GridColumnStyles[3].NullText = String.Empty;
......................
// DataGridButtonAction function runs when the datagrid ButtonColumnStyle's
// Button control is clicked. The function receives two arguments:
// ColumnMappingName and ColumnValueAtRow of String type
public void DataGridButtonAction(String ColumnMappingName, String ColumnValueAtRow)
{
// You can identify datagrid column mapping name.
// It gives you ability to put several datagrid Button ColumnStyles on the same datagrid
if (ColumnMappingName == "City") {
String strValue;
if (DataGrid1[DataGrid1.CurrentRowIndex, 3] == DBNull.Value) {
strValue = "Nothing :(";
}
else {
strValue = ColumnValueAtRow + " city, " + DataGrid1[DataGrid1.CurrentRowIndex, 2] + "!";
}
MessageBox.Show("You have chosen " + strValue, "DataGrid Button is clicked!");
}
}
|
 .Net DataGrid Memo column Style.
DataGridMemoColumn style gives you a useful Memo Field control, which presents an edit window when user selects a cell of the DataGrid Memo Column on .NET DataGrid. This provides a pop-up memo field editor that you can call from your code at any time to let users edit the text in a memo field.
This Memo field editor provides more flexibility by updating the memo field to be used in a .NET DataGrid column.
The DataGrid Memo Column Memo field editor is useful for showing short document contents, like memos and emails.
When using the DataGrid Memo Column editor you are automatically provided with all general features, which any typical, contemporary word processor has.
|
 .Net DataGrid DateTimePicker column Style.
The DateTimePicker ColumnStyle is used to allow the user to select a date and time, and to display that date/time in your DataGrid.
|
 How to Trap the Tab Key in a .NET Control?
You are trying to create a control in .NET, and your control has to catch the Tab key. It might be a grid, where you would expect Tab to move between cells, or it might be an editor control. Now you would like to catch Tab and some other navigation keys that do not call OnKeyDown or OnKeyUp. How to intercept Tabs properly in .NET?
You have to create a class that inherits from the System.Windows.Forms.Control and override the ProcessKeyMessage method. This method is called when a control receives a keyboard message. You suppose to trap the Tab on your Button. Just override the System.Windows.Forms.Button class and create your own myButton class:
|
In your custom code you will be able to identify which key has been pressed before your button was activated:
|
if (System.Windows.Forms.Keys.Tab.Equals(myButton.PreProcessKey)) MessageBox.Show("Tab is pressed!");
|
 How to format a datagrid column using Numeric, DateTime formats? How to mask data in the column?
These formatted intelligent DateTimeColumn, NumericColumn, TextFractionsColumn style controls can mask the date, time, numbers, digits, decimal as well as the text fractions. It gives you ability to manage the IP Address, SS#, Phone numbers, etc., and checks the validation, and automatically set the delimiter location.
|
// Set datagrid DateTime ColumnStyle for TimeFirst field
TblStyle.GridColumnStyles.Add(new DataGridDateTimeColumn(DateTimeTextBox.Stencils.HHMM24, DateTime.Now, ":"));
//TblStyle.GridColumnStyles.Add(new DataGridTextBoxColumn());
TblStyle.GridColumnStyles[6].MappingName = "TimeFirst";
TblStyle.GridColumnStyles[6].HeaderText = "Time";
TblStyle.GridColumnStyles[6].Width = 40;
TblStyle.GridColumnStyles[6].NullText = String.Empty;
// Set datagrid Numeric ColumnStyle for Price field
TblStyle.GridColumnStyles.Add(new DataGridNumericColumn(false, true, null, null, 1000000, null, 2));
//TblStyle.GridColumnStyles.Add(new DataGridTextBoxColumn());
TblStyle.GridColumnStyles[7].MappingName = "Price";
TblStyle.GridColumnStyles[7].HeaderText = "Price";
TblStyle.GridColumnStyles[7].Width = 60;
TblStyle.GridColumnStyles[7].NullText = String.Empty;
// Set datagrid TextFractions ColumnStyle for Phone field
TblStyle.GridColumnStyles.Add(new DataGridTextFractionsColumn());
TblStyle.GridColumnStyles[8].MappingName = "Phone";
TblStyle.GridColumnStyles[8].HeaderText = "Phone";
TblStyle.GridColumnStyles[8].Width = 80;
TblStyle.GridColumnStyles[8].NullText = String.Empty;
// Add TableStyle
DataGrid1.TableStyles.Add(TblStyle);
// Define NumericColumn DataGridNumericColumn object for Price field
DataGridNumericColumn NumericColumn = (DataGridNumericColumn) DataGrid1.TableStyles[0].GridColumnStyles[7];
// Specify back color for the field
NumericColumn.txtBox.box.BackColor = System.Drawing.Color.LightPink;
// Identify PhoneColumn object that is the DataGridTextFractionsColumn?s ?child?
DataGridTextFractionsColumn PhoneColumn = (DataGridTextFractionsColumn) DataGrid1.TableStyles[0].GridColumnStyles[8];
// Specify Delimiter Character for the field
PhoneColumn.txtBox.box.DelimiterChar = "-";
// Specify first fraction properties
// Alphanumeric symbols only are acceptable for the fraction
PhoneColumn.txtBox.box.FractionsCode[0, 0] = "a";
// You can insert 3 symbols only into the first fraction
PhoneColumn.txtBox.box.FractionsCode[0, 1] = 3;
// Specify second fraction properties
// Numeric symbols only are acceptable for the fraction
PhoneColumn.txtBox.box.FractionsCode[1, 0] = "n";
// You can insert 3 symbols only into the second fraction
PhoneColumn.txtBox.box.FractionsCode[1, 1] = 3;
// Specify third fraction properties
// Numeric symbols only are acceptable for the fraction
PhoneColumn.txtBox.box.FractionsCode[2, 0] = "n";
// You can insert 4 symbols only into the third fraction
PhoneColumn.txtBox.box.FractionsCode[2, 1] = 4;
// To specify Password column only one text fraction must be defined:
// To let accept any symbols for the fraction we need leave first array element empty:
//PhoneColumn.txtBox.box.FractionsCode[0, 0] = "";
// You can insert 30 symbols only into the password fraction
//PhoneColumn.txtBox.box.FractionsCode[0, 1] = 30;
// Specify Password Character for the field
//PhoneColumn.txtBox.box.PasswordChar = "*";
|
 How to implement a .NET application with the DataGrid Print class?
The DataGrid Print class is intended to help you create a print output based on your .NET datagrid content. The class has been included into the DataGrid Columns .NET assembly since it is build for .NET WinForms datagrid control and very helpful for your .NET datagrid design. It helps you to implement a .NET Windows Forms application with a print preview and a print support.
The following example creates a DataGridPrint object.
|
|
|
|
|
|
environment and programming model for constructing a range of software solutions. RustemSoft develops the assemblies (dll) for .NET developers. With the RustemSoft .NET assemblies and controls, customers gained the benefits of enhanced tool and framework functionality for building enterprise-critical software.
RustemSoft?s .NET programming components are reducing the amount of code required to accomplish common tasks and delivering high-end features for advanced .NET developers.
RustemSoft presents DataGridColumns .NET assembly for VB.NET, C#, C++, J# the intelligent software package designed for .NET developers.
A quantity of jobs you may want to achieve with the Windows Forms DataGrid control are, unexpectedly, more troublesome than you might expect. Principally, this is because the Windows Forms DataGrid control is column-based, rather than cell-based. As a result, to attain most tasks, you have to work with the columns, not the cells themselves.
DataGridColumns .NET assembly from RustemSoft is a DataGrid Columns Styles software package specifically designed for .NET developers. The assembly allows you to use all strengths of the MS Windows .NET forms DataGrid control without waiving the user interface elements your customers need.
|
|
|