|
DataGridViewColumns .NET assembly (for VB.NET, C#, C++)
|
|
The DataGridView .NET control seems a lot better than DataGrid .NET 1.x control. It provides a powerful and flexible way to display a data source. You can extend the DataGridView control in a number of ways to build custom behaviors into your applications. Although you can create your own types of cells the Windows Forms DataGridView control is mostly column-based, rather than cell-based. As a result, to attain most tasks, you have to work with the columns, not the cells themselves.
|
|
DataGridViewColumns .NET assembly from Rustemsoft is a DataGridView Columns software package specifically designed for .NET developers. The assembly allows you to use all strengths of the MS Windows .NET forms DataGridView control without waiving the user interface elements your customers need.
These Column classes are chock full of functionality that you won’t find in the standard Microsoft .NET DataGridView Columns, that make it easy to build professional and forcing user interfaces.
|
|
|
By using the assembly you can create your own set of DataGridViewColumn objects that defines custom column for the Windows Forms DataGridView control and add them to the GridColumnsCollection.
A column is an object that defines what the column looks and behaves like, including such things as color, font, and the presence of controls that will handle linked field in a database with the use of a Combo Box, a DateTime format Box and other control.
Also we have built .NET code samples that describe the concepts and techniques that you can use to build DataGridView features into your applications.
|
|
|
The .NET Framework includes six types of DataGridView column classes by default: DataGridViewButtonColumn, DataGridViewCheckBoxColumn, DataGridViewComboboxColumn, DataGridViewImageColumn, DataGridViewTextBoxColumn, and DataGridViewLinkColumn classes.
Rustemsoft DataGridViewColumns dynamic link library contains the following DataGridView Columns:
|
| The following example creates a DataGridViewComboColumn object and adds it to the DataGridView layout.
|
| ' Set DataGridView Combo Column for CarID field
|
| Dim ColumnCar As New DataGridViewComboColumn
|
| ' DataGridView Combo ValueMember field has name "CarID"
|
| ' DataGridView Combo DisplayMember field has name "Car"
|
| .DataPropertyName = "CarID"
|
| ' Bind ColumnCar to Cars table
|
| .box.DataSource = ds.Tables("Cars")
|
| .box.ValueMember = "CarID"
|
| .box.DisplayMember = "Car"
|
| // Set DataGridView Combo Column for CarID field
|
| DataGridViewComboColumn ColumnCar = new DataGridViewComboColumn();
|
| // DataGridView Combo ValueMember field name is "CarID"
|
| // DataGridView Combo DisplayMember field name is "Car"
|
| ColumnCar.DataPropertyName = "CarID";
|
| ColumnCar.HeaderText = "Car Name";
|
| // Bind ColumnCar to Cars table
|
| ColumnCar.box.DataSource = ds.Tables["Cars"];
|
| ColumnCar.box.ValueMember = "CarID";
|
| ColumnCar.box.DisplayMember = "Car";
|
| // Add ColumnCar onto DataGridView layout
|
| DataGridView1.Columns.Add(ColumnCar);
|
DataGridView Memo column
The Rustemsoft DataGridViewMemoColumn gives you a useful Memo Field control, which presents an edit window when user selects a cell of the DataGridView Memo Column on .NET DataGridView. 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 DataGridView column.
The DataGridView Memo Column Memo field editor is useful for showing short document contents, like memos and emails.
When using the DataGridView Memo Column editor you are automatically provided with all general features, which any typical, contemporary word processor has.
|
| The following example creates a DataGridViewMemoColumn and adds it into the DataGridView layout.
|
| ' Set DataGridView Memo Column for Remark field
|
| Dim ColumnMemo As New DataGridViewMemoColumn
|
| .DataPropertyName = "Remark"
|
| .box.showCancelButton = False
|
| .box.Caption = "Edit Memo field text"
|
| DataGridView1.Columns.Add(ColumnMemo)
|
| // Set DataGridView Memo Column for Remark field
|
| DataGridViewMemoColumn ColumnMemo = new DataGridViewMemoColumn();
|
| ColumnMemo.DataPropertyName = "Remark";
|
| ColumnMemo.HeaderText = "Remark";
|
| ColumnMemo.box.showCancelButton = false;
|
| ColumnMemo.box.Caption = "Edit Memo field text";
|
| // Add ColumnMemo onto DataGridView layout
|
| DataGridView1.Columns.Add(ColumnMemo);
|
DataGridView DateTimePicker column
The DateTimePicker Column is used to allow the user to select a date and time, and to display that date/time in your DataGridView.
|
| |
You can limit the dates and times that can be selected by setting the MinDate and MaxDate properties.
You can change the look of the calendar portion of the control by setting the CalendarForeColor, CalendarFont, CalendarTitleBackColor, CalendarTitleForeColor, CalendarTrailingForeColor, and CalendarMonthBackground properties.
The Format property sets the DateTimePickerFormat of the control. The default date Format is DateTimePickerFormat.Long. If the Format property is set to DateTimePickerFormat.Custom, you can create your own format style by setting the CustomFormat property and building a custom format string. The custom format string can be a combination of custom field characters and other literal characters. For example, you can display the date as "June 01, 2001 - Friday" by setting the CustomFormat property to "MMMM dd, yyyy - dddd".
box - one of the main properties of the DataGridViewDateTimePickerColumn class. The box is DateTimePicker object in selected cell. It gets the hosted box control that is an overridden instance of the DateTimePicker control.
|
Syntax
DataGridViewDateTimePicker()
|
| The following example creates a DataGridViewDateTimePicker object and adds it into the DataGridView layout.
|
| ' Define ColumnPicker DateTime Picker Column with WithEvents keyword
|
| Private WithEvents ColumnPicker As New DataGridViewDateTimePickerColumn
|
| ' Set DataGridView DateTimePicker Column for DateFirst field
|
| ' The ColumnPicker DateTime Picker Column is defined above with WithEvents keyword to make
|
| ' the column object visible in the whole class scope. The WithEvents keyword indicates
|
| ' that a declared object variable refers to a class instance that can raise events.
|
| .DataPropertyName = "DateFirst"
|
| ' Identify whole column back and fore colors
|
| .CellTemplate.Style.BackColor = Color.LightPink
|
| .CellTemplate.Style.ForeColor = Color.DarkBlue
|
| ' Identify column selected calendar back and foreground color
|
| .box.CalendarForeColor = Color.Red
|
| .box.CalendarMonthBackground = Color.PowderBlue
|
| ' Identify whole column DateTime format to display in each inactive column
|
| .DateTimeDisplayFormat = DateTimeStencils.MMDDYY
|
| '' for European people (you can see the date as "31.12.2008"):
|
| 'System.Threading.Thread.CurrentThread.CurrentCulture = New Globalization.CultureInfo("de-DE")
|
| '.DateTimeEditFormat = DateTimePickerFormat.Custom
|
| '.box.CustomFormat = "dd.MM.yy"
|
| '.DateTimeDisplayFormat = Stencils.DDMMYY
|
| '' !!! To empty a DateTimePickerColumn cell just push Delete or
|
| '' click the right mouse button when the cell is selected !!!
|
| .Columns.Add(ColumnPicker)
|
| // Define ColumnPicker DateTime Picker Column
|
| internal DataGridViewDateTimePickerColumn ColumnPicker = new DataGridViewDateTimePickerColumn();
|
| // Set DataGridView DateTimePicker Column for DateFirst field
|
| // The ColumnPicker Column is defined above to make the column object visible in the whole
|
| // class scope. The declared object variable refers to a class instance that can raise events.
|
| ColumnPicker.DataPropertyName = "DateFirst";
|
| ColumnPicker.HeaderText = "Date";
|
| // Identify whole column back and fore colors
|
| ColumnPicker.CellTemplate.Style.BackColor = Color.LightPink;
|
| ColumnPicker.CellTemplate.Style.ForeColor = Color.DarkBlue;
|
| // Identify column selected calendar back and foreground color
|
| ColumnPicker.box.CalendarForeColor = Color.Red;
|
| ColumnPicker.box.CalendarMonthBackground = Color.PowderBlue;
|
| // Identify whole column DateTime format to display in each inactive column
|
| ColumnPicker.DateTimeDisplayFormat = DateTimeStencils.MMDDYY;
|
| // for European people (you can see the date as "31.12.2008"):
|
| System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
|
| ColumnPicker.DateTimeEditFormat = DateTimePickerFormat.Custom;
|
| ColumnPicker.box.CustomFormat = "dd.MM.yy";
|
| ColumnPicker.DateTimeDisplayFormat = DateTimeStencils.DDMMYY;
|
| ColumnPicker.DelimiterChar = ".";
|
| // !!! To empty a DateTimePickerColumn cell just push Delete or
|
| // click the right mouse button when the cell is selected !!!
|
| // Add ColumnPicker column LeaveEvent Handler
|
| ColumnPicker.Leave += new DataGridViewDateTimePickerColumn.LeaveEventHandler(ColumnPicker_Leave);
|
| // Add ColumnPicker onto DataGridView layout
|
| DataGridView1.Columns.Add(ColumnPicker);
|
| The following example creates a DataGridViewDateTimeColumn and adds it into the DataGridView layout.
|
| ' Set datagrid DateTime Column for TimeFirst field
|
| Dim ColumnTime As New DataGridViewDateTimeColumn
|
| .DataPropertyName = "TimeFirst"
|
| ' Identify selected cell's DateTime format to edit
|
| .box.DateTimeFormat = DateTimeStencils.HHMM12
|
| ' Identify whole column DateTime format to display in each inactive column
|
| .DateTimeDisplayFormat = DateTimeStencils.HHMM12
|
| ' Specify Delimiter Character for the field
|
| .box.DefaultValue = New DateTime(2000, 5, 26, 11, 11, 11)
|
| ' Identify column selected cell back and foreground color
|
| .box.BackColor = Color.LightGray
|
| .box.ForeColor = Color.DarkRed
|
| ' Define cell warning color
|
| .box.ProblemColor = Color.LightPink
|
| ' Identify whole column back and fore colors
|
| .CellTemplate.Style.BackColor = Color.Ivory
|
| .CellTemplate.Style.ForeColor = Color.DarkBlue
|
| ' Define cell border style
|
| .box.BorderStyle = BorderStyle.None
|
| ' You may turn error messages off
|
| 'ColumnTime.box.ErrMessageVisible = False
|
| DataGridView1.Columns.Add(ColumnTime)
|
| // Set datagrid DateTime Column for TimeFirst field
|
| DataGridViewDateTimeColumn ColumnTime = new DataGridViewDateTimeColumn();
|
| ColumnTime.DataPropertyName = "TimeFirst";
|
| ColumnTime.HeaderText = "Time";
|
| // Identify selected cell's DateTime format to edit
|
| ColumnTime.box.DateTimeFormat = DateTimeStencils.HHMM12;
|
| // Identify whole column DateTime format to display in each inactive column
|
| ColumnTime.DateTimeDisplayFormat = DateTimeStencils.HHMM12;
|
| // Specify Delimiter Character for the field
|
| ColumnTime.box.DelimiterChar = ".";
|
| ColumnTime.box.DefaultValue = new DateTime(2000, 5, 26, 11, 11, 11).ToString();
|
| // Identify column selected cell back and foreground color
|
| ColumnTime.box.BackColor = Color.LightGray;
|
| ColumnTime.box.ForeColor = Color.DarkRed;
|
| // Define cell warning color
|
| ColumnTime.box.ProblemColor = Color.LightPink;
|
| // Identify whole column back and fore colors
|
| ColumnTime.CellTemplate.Style.BackColor = Color.Ivory;
|
| ColumnTime.CellTemplate.Style.ForeColor = Color.DarkBlue;
|
| // Define cell border style
|
| ColumnTime.box.BorderStyle = BorderStyle.None;
|
| // You may turn error messages off
|
| //ColumnTime.box.ErrMessageVisible = False;
|
| // Add ColumnTime onto DataGridView layout
|
| DataGridView1.Columns.Add(ColumnTime);
|
Syntax
DataGridViewTimeUpDownColumn()
|
| The following example creates a DataGridViewNumericColumn and adds it into the DataGridView layout.
|
| ' Set datagrid Numeric Column for Price field
|
| Dim NumericColumn As New DataGridViewNumericColumn
|
| .DataPropertyName = "Price"
|
| ' Define some Numeric Box specific properties
|
| ' Identify column selected cell back and foreground colors
|
| .box.BackColor = Color.LightGray
|
| .box.ForeColor = Color.DarkRed
|
| ' Define cell warning color
|
| .box.ProblemColor = Color.LightPink
|
| ' Identify whole column back and fore colors
|
| .CellTemplate.Style.BackColor = Color.WhiteSmoke
|
| .CellTemplate.Style.ForeColor = Color.Brown
|
| .CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight
|
| ' Define cell border style
|
| .box.BorderStyle = BorderStyle.Fixed3D
|
| ' Assign selected cell's font
|
| .box.Font = New Font("Tahoma", 8, FontStyle.Bold)
|
| DataGridView1.Columns.Add(NumericColumn)
|
| // Set datagrid Numeric Column for Price field
|
| DataGridViewNumericColumn NumericColumn = new DataGridViewNumericColumn();
|
| NumericColumn.DataPropertyName = "Price";
|
| NumericColumn.HeaderText = "Price";
|
| NumericColumn.Width = 60;
|
| // Identify column selected cell back and foreground colors
|
| NumericColumn.box.BackColor = Color.LightGray;
|
| NumericColumn.box.ForeColor = Color.DarkRed;
|
| // Define cell warning color
|
| NumericColumn.box.ProblemColor = Color.LightPink;
|
| // Identify whole column back and foreground colors
|
| NumericColumn.CellTemplate.Style.BackColor = Color.WhiteSmoke;
|
| NumericColumn.CellTemplate.Style.ForeColor = Color.Brown;
|
| NumericColumn.CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
|
| // Define cell border style
|
| NumericColumn.box.BorderStyle = BorderStyle.Fixed3D;
|
| // Assign selected cell's font
|
| NumericColumn.box.Font = new Font("Tahoma", 8, FontStyle.Bold);
|
| // Add NumericColumn onto DataGridView layout
|
| DataGridView1.Columns.Add(NumericColumn);
|
Up to 5 text fractions can be defined. By setting the DelimiterChar property up a delimiter symbol for the control can be specified. You can define the overall length of each text fraction and what kind of characters can be inserted in the fraction (alphanumeric, numeric only, etc.).
Syntax
DataGridViewTextFractionsColumn()
|
To identify each text fraction you must set values of ten properties where settings of the fractions are stored. The first five properties (I_stFractionFormat, II_ndFractionFormat, IIIrdFractionFormat, IVthFractionFormat, and VthFractionFormat) specifies what characters can be inserted into the fraction. It accepts the following values of FractionFormats enumeration:
None - format is not assigned
Numeric - numeric characters (0-9) are acceptable only
Letters - letters (Aa-Zz) are acceptable only
Alphanumeric - alphanumeric characters (Aa-Zz0-9) are acceptable only
Punctuation - punctuation characters are acceptable only
Spaces - spaces are acceptable only
AnyCharacters - any characters are acceptable
The second five box specific properties (I_stFractionLength, II_ndFractionLength, IIIrdFractionLength, IVthFractionLength, and VthFractionLength) specifies overall fraction's length.
|
| The following example creates a DataGridViewTextFractionsColumn and adds it to the DataGridView layout.
|
| ' Set DataGridView Text Fractions Column for Phone field
|
| Dim MaskColumn As New DataGridViewFractionColumn
|
| .DataPropertyName = "Phone"
|
| ' selected cell has 3 fractions delimited by '-' char
|
| ' Define 1st fraction's parameters
|
| ' Numeric symbols only are acceptable for the fraction
|
| .box.I_stFractionFormat = FractionFormats.Numeric
|
| ' You can insert 3 symbols only into the first fraction
|
| .box.I_stFractionLength = 3
|
| ' Define 2nd fraction's parameters
|
| ' Numeric symbols only are acceptable for the fraction
|
| .box.II_ndFractionFormat = FractionFormats.Numeric
|
| ' You can insert 3 symbols only into the second fraction
|
| .box.II_ndFractionLength = 3
|
| ' Define 3rd fraction's parameters
|
| ' Numeric symbols only are acceptable for the fraction
|
| .box.IIIrdFractionFormat = FractionFormats.Numeric
|
| ' You can insert 4 symbols only into the third fraction
|
| .box.IIIrdFractionLength = 4
|
| ' Specify Delimiter Character for the field
|
| .box.DefaultValue = "911-911-0911"
|
| ' Identify column selected cell back and foreground colors
|
| .box.BackColor = Color.LightGray
|
| .box.ForeColor = Color.DarkRed
|
| ' Define cell warning color
|
| .box.ProblemColor = Color.LightPink
|
| ' Identify whole column back and foreground colors
|
| .CellTemplate.Style.BackColor = Color.WhiteSmoke
|
| .CellTemplate.Style.ForeColor = Color.Brown
|
| .CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight
|
| ' Define selected cell border style
|
| .box.BorderStyle = BorderStyle.Fixed3D
|
| ' Define selected cell's font
|
| .box.Font = New Font("Tahoma", 8, FontStyle.Bold)
|
| ' You may turn error messages off
|
| '.box.ErrMessageVisible = False
|
| ' You can specify an error message in your native language:
|
| '.box.ErrorMessage = "Veuillez écrire les nombres seulement!"
|
| DataGridView1.Columns.Add(MaskColumn)
|
| // Set DataGridView Text Fractions Column for Phone field
|
| DataGridViewFractionColumn MaskColumn = new DataGridViewFractionColumn();
|
| MaskColumn.DataPropertyName = "Phone";
|
| MaskColumn.HeaderText = "Phone";
|
| // selected cell has 3 fractions delimited by '-' char
|
| // Define 1st fraction's parameters
|
| // Numeric symbols only are acceptable for the fraction
|
| MaskColumn.box.I_stFractionFormat = FractionFormats.Numeric;
|
| // You can insert 3 symbols only into the first fraction
|
| MaskColumn.box.I_stFractionLength = 3;
|
| // Define 2nd fraction's parameters
|
| // Numeric symbols only are acceptable for the fraction
|
| MaskColumn.box.II_ndFractionFormat = FractionFormats.Numeric;
|
| // You can insert 3 symbols only into the second fraction
|
| MaskColumn.box.II_ndFractionLength = 3;
|
| // Define 3rd fraction's parameters
|
| // Numeric symbols only are acceptable for the fraction
|
| MaskColumn.box.IIIrdFractionFormat = FractionFormats.Numeric;
|
| // You can insert 4 symbols only into the third fraction
|
| MaskColumn.box.IIIrdFractionLength = 4;
|
| // Specify Delimiter Character for the field
|
| MaskColumn.box.DelimiterChar = "-";
|
| MaskColumn.box.DefaultValue = "911-911-0911";
|
| // Identify column selected cell back and foreground colors
|
| MaskColumn.box.BackColor = Color.LightGray;
|
| MaskColumn.box.ForeColor = Color.DarkRed;
|
| // Define cell warning color
|
| MaskColumn.box.ProblemColor = Color.LightPink;
|
| // Identify whole column back and foreground colors
|
| MaskColumn.CellTemplate.Style.BackColor = Color.WhiteSmoke;
|
| MaskColumn.CellTemplate.Style.ForeColor = Color.Brown;
|
| MaskColumn.CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
|
| // Define cell border style
|
| MaskColumn.box.BorderStyle = BorderStyle.Fixed3D;
|
| // Assign selected cell font to edit
|
| MaskColumn.box.Font = new Font("Tahoma", 8, FontStyle.Bold);
|
| // You may turn error messages off
|
| //ColumnFraction.box.ErrMessageVisible = False;
|
| // You can specify an error message in your native language:
|
| //ColumnFraction.box.ErrorMessage = "Veuillez écrire les nombres seulement!";
|
| // Add MaskColumn onto DataGridView layout
|
| DataGridView1.Columns.Add(MaskColumn);
|
| The following example creates a DataGridViewLabelColumn and adds it to the DataGridView layout.
|
| ' Define ColumnLabel Label Column with WithEvents keyword
|
| Private WithEvents ColumnLabel As New DataGridViewLabelColumn
|
| ' Set DataGridView Label Column for ID field
|
| ' The ColumnLabel Label Column is defined above with WithEvents keyword to make the
|
| ' column object visible in the whole class scope. The WithEvents keyword indicates
|
| ' that a declared object variable refers to a class instance that can raise events.
|
| ' Identify LabelColumn selected cell backcolor
|
| .box.BackColor = Color.LightSalmon
|
| ' Identify whole LabelColumn back and fore colors
|
| .CellTemplate.Style.BackColor = Color.Lavender
|
| .CellTemplate.Style.ForeColor = Color.DarkBlue
|
| .box.BorderStyle = BorderStyle.FixedSingle
|
| .box.Font = New Font("Tahoma", 8, FontStyle.Bold)
|
| DataGridView1.Columns.Add(ColumnLabel)
|
| // Define ColumnLabel Label Column
|
| internal DataGridViewLabelColumn ColumnLabel = new DataGridViewLabelColumn();
|
| // Set DataGridView Label Column for ID field
|
| // The ColumnLabel Label Column is defined above to make the column object visible in the whole
|
| // class scope. The declared object variable refers to a class instance that can raise events.
|
| ColumnLabel.DataPropertyName = "ID";
|
| ColumnLabel.HeaderText = "ID";
|
| // Identify LabelColumn selected cell backcolor
|
| ColumnLabel.box.BackColor = Color.LightSalmon;
|
| // Identify whole LabelColumn back and fore colors
|
| ColumnLabel.CellTemplate.Style.BackColor = Color.Lavender;
|
| ColumnLabel.CellTemplate.Style.ForeColor = Color.DarkBlue;
|
| ColumnLabel.box.BorderStyle = BorderStyle.FixedSingle;
|
| ColumnLabel.box.Font = new Font("Tahoma", 8, FontStyle.Bold);
|
| // Add ColumnLabel ClickEvent Handler
|
| ColumnLabel.Click += new DataGridViewLabelColumn.ClickEventHandler(this.ColumnLabel_Click);
|
| // Add ColumnLabel onto DataGridView layout
|
| DataGridView1.Columns.Add(ColumnLabel);
|
| The following example creates DataGridViewDomainUpDownColumn object and adds it into the DataGridView layout. The column is populated from a DataTable object that belongs to a customized DataSet.
|
| ' Set DataGridView DomainUpDown Column for State field
|
| Dim DomainColumn As New DataGridViewDomainUpDownColumn
|
| .DataPropertyName = "State"
|
| ' Bind DomainColumn to SamplesDataSet.States table
|
| .DataSource = SamplesDataSet.States
|
| DataGridView1.Columns.Add(DomainColumn)
|
| // Set DataGridView DomainUpDown Column for State field
|
| DataGridViewDomainUpDownColumn DomainColumn = new DataGridViewDomainUpDownColumn();
|
| DomainColumn.DataPropertyName = "State";
|
| DomainColumn.HeaderText = "State";
|
| // Bind DomainColumn to SamplesDataSet.States table
|
| DomainColumn.DataSource = samplesDataSet.States;
|
| DomainColumn.DisplayMember = "State";
|
| // Add DomainColumn onto DataGridView layout
|
| DataGridView1.Columns.Add(DomainColumn);
|
Syntax
DataGridViewNumericUpDownColumn()
|
| The following example creates a DataGridViewNumericUpDownColumn and adds it to the DataGridView layout.
|
| ' Set DataGridView NumericUpDown Column for Percent field
|
| Dim UpDnColumn As New DataGridViewNumericUpDownColumn
|
| .DataPropertyName = "Percent"
|
| ' Set the Minimum, Maximum, and initial Value.
|
| // Set DataGridView NumericUpDown Column for Percent field
|
| DataGridViewNumericUpDownColumn UpDnColumn = new DataGridViewNumericUpDownColumn();
|
| UpDnColumn.DataPropertyName = "Percent";
|
| UpDnColumn.HeaderText = "%%";
|
| // Set the Minimum, Maximum, and initial Value.
|
| UpDnColumn.box.Value = 5;
|
| UpDnColumn.box.Maximum = 2500;
|
| UpDnColumn.box.Minimum = - 100;
|
| // Add UpDnColumn onto DataGridView layout
|
| DataGridView1.Columns.Add(UpDnColumn);
|
Syntax
DataGridViewPictureColumn()
|
| The following example creates a DataGridViewPictureColumn and adds it to the DataGridView layout.
|
| ' Define ColumnPicture Picture Column with WithEvents keyword
|
| Private WithEvents ColumnPicture As New DataGridViewPictureColumn()
|
| ' Set DataGridView Picture Column for Picture field
|
| ' The ColumnPicture Picture Column is defined above with WithEvents keyword to make
|
| ' the column object visible in the whole class scope. The WithEvents keyword indicates
|
| ' that a declared object variable refers to a class instance that can raise events.
|
| .DataPropertyName = "Picture"
|
| ' Specify path to a directory where image files are stored
|
| .PicturesPath = AppPath + "images\"
|
| DataGridView1.Columns.Add(ColumnPicture)
|
| // Define ColumnPicture Picture Column
|
| internal DataGridViewPictureColumn ColumnPicture = new DataGridViewPictureColumn();
|
| // Set DataGridView Picture Column for Picture field
|
| // The ColumnPicture Picture Column is defined above to make the column object visible in the whole
|
| // class scope. The declared object variable refers to a class instance that can raise events.
|
| ColumnPicture.DataPropertyName = "Picture";
|
| ColumnPicture.HeaderText = "Picture";
|
| ColumnPicture.Width = 50;
|
| // Specify path to a directory where image files are stored
|
| ColumnPicture.PicturesPath = AppPath + "images";
|
| // Add ColumnPicture Click Event Handler
|
| ColumnPicture.Click += new DataGridViewPictureColumn.ClickEventHandler(ColumnPicture_Click);
|
| // Add ColumnPicture onto DataGridView layout
|
| DataGridView1.Columns.Add(ColumnPicture);
|
Each editable mask position, representing a required or optional input, is shown with a single prompt char. For example, the number sign # is often used as a placeholder for a numeric character input. You can use the PromptChar property to specify a custom prompt character. The HidePromptOnLeave property determines if the user sees the prompt characters when the DataGridView MaskedTextBox Column cell loses input focus.
Syntax
DataGridViewMaskedTextBoxColumn()
|
| The following example creates a DataGridViewMaskedTextBoxColumn and adds it into the DataGridView layout.
|
| ' Set DataGridView MaskedTextBox Column for ZipCode field
|
| Dim ColumnMaskedTextBox As New DataGridViewMaskedTextBoxColumn
|
| .DataPropertyName = "ZipCode"
|
| .box.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals
|
| ' Identify column selected cell back and foreground colors
|
| .box.BackColor = Color.Lavender
|
| .box.ForeColor = Color.DarkOrchid
|
| ' Identify whole column back and foreground colors
|
| .CellTemplate.Style.BackColor = Color.WhiteSmoke
|
| .CellTemplate.Style.ForeColor = Color.Brown
|
| .CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight
|
| ' Define selected cell border style
|
| .box.BorderStyle = BorderStyle.Fixed3D
|
| ' Define selected cell's font
|
| .box.Font = New Font("Tahoma", 8, FontStyle.Bold)
|
| DataGridView1.Columns.Add(ColumnMaskedTextBox)
|
| // Set DataGridView MaskedTextBox Column for ZipCode field
|
| DataGridViewMaskedTextBoxColumn ColumnMaskedTextBox = new DataGridViewMaskedTextBoxColumn();
|
| ColumnMaskedTextBox.DataPropertyName = "ZipCode";
|
| ColumnMaskedTextBox.HeaderText = "Zip Code";
|
| ColumnMaskedTextBox.Width = 100;
|
| ColumnMaskedTextBox.box.Mask = "99999-9999";
|
| ColumnMaskedTextBox.box.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
|
| // Identify column selected cell back and foreground colors
|
| ColumnMaskedTextBox.box.BackColor = Color.Lavender;
|
| ColumnMaskedTextBox.box.ForeColor = Color.DarkOrchid;
|
| // Identify whole column back and foreground colors
|
| ColumnMaskedTextBox.CellTemplate.Style.BackColor = Color.WhiteSmoke;
|
| ColumnMaskedTextBox.CellTemplate.Style.ForeColor = Color.Brown;
|
| ColumnMaskedTextBox.CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
|
| // Define selected cell border style
|
| ColumnMaskedTextBox.box.BorderStyle = BorderStyle.Fixed3D;
|
| // Define selected cell's font
|
| ColumnMaskedTextBox.box.Font = new Font("Tahoma", 8, FontStyle.Bold);
|
| // Add ColumnMaskedTextBox onto DataGridView layout
|
| DataGridView1.Columns.Add(ColumnMaskedTextBox);
|
Obviously the DataGridViewPrint class is not a DataGridView column control. The service class is intended to help you to create a print output based on your DataGridView content. The class has been included into assembly since it is build for .NET WinForms DataGridView control and very helpful for your .NET DataGridView design. It will help you to implement an application with a print preview and a print support.
The DataGridViewPrint class is used by the Print dialog and Print Preview dialog (on your .NET form) to draw the DataGridView object content that should be printed. An object of the class is used for a .NET PrintDocument object.
|
Syntax
DataGridViewPrint(PrintDocument1, DataGridView1, bBlackWhite)
PrintDocument1 - System.Drawing.Printing.PrintDocument reusable object that sends output to a printer
DataGridView1 - System.Windows.Forms.DataGridView object that content you are going to print
bBlackWhite - boolean parameter that defines if you like to use "Black and White" printing mode or you would like to send to printer the real coloring that your DataGridView control has currently on your form.
|
|
|
|