Documents
NextGrid & NextDBGrid
- Html Column Tutorial
- Upgrade existing projects for loading changes
- Edit events in NextGrid
- NextGrid Vista Style
- NextGrid How To
- Integrating Inplace Editors
- NextGrid Slide Style Tutorial
- InputLine Tutorial
- FieldChooser Tutorial
- Using Editors in runtime
- Grid Report Tutorial
NextGrid
- TreeColumn Tutorial
- NextGrid Quick Start
- Custom Draw in NextGrid
- Export to XML from NextGrid
- Optimize NextGrid
- NextGrid Custom Sorting
- VirtualColumn Tutorial
- Graphic Column Tutorial
NextDBGrid
- NextDBGrid Quick Start
- NextDBGrid Events
- NextDBGrid How To
- Sorting records in NextDBGrid
- LookupColumn Tutorial
NextInspector
- NextInspector Advanced tutorial
- ToolbarItem tutorial
- NextDBInspector Tutorial
- NextInspector Item Types
- Map VCL property to item
- NextInspector Quick Start
NextSheet
NextCollection
- NxAlertWindow Tutorial
- NxInfoPanel Tutorial
- Vista Styled Panels
- NxPathControl and NxNotebook tutorial
- NxPathControl Quick Start
- NxFlipPanel and NxHeaderPanel Quick Start
- NxOutlookBar Tutorial
- NxPageControl and NxNotebook Quick Start
- NxButton Tutorial
Misc
- Component Names Change
- NxComboBox styles
- Numeric FormatMask
- NxVirtualDataSet tutorial
- DateTime FormatMask
- NxPreview Quick Start
- 32bit Bitmaps Tutorial
- Quick update
- Enable typing unicode characters in InplaceEditors
- Using NxColorScheme
- NxProgress Tutorial
- NxAutoCompletion Tutorial
Labs
NextGrid .NET
NextGrid dot NET How To
Related Articles:
Info
- Skill:
- Version: 1.0.0
- Author: Bojan Nikolic
- Created: 2010-09-15
- Updated: 2011-02-06
Content:
1. Add column in run-time
2. Paint even and odd rows in different colors
3. Set grid lines color dynamically
4. Access to the newly added row
5. Enable search-as-you-type for column
6. How to access to a cell
1. Add column in run-time
Best practice for adding new column into grid is to create column object, set column properties and then add it into grid.
using NextSuite; ... TextColumn Column; Column = new TextColumn(); // Create column object Column.Header.Alignment = HorizontalAlignment.Center; Column.Header.Text = "Sample Header"; nextGrid1.Columns.Add(Column); // Add column into grid
2. Paint even and odd rows in different colors
In NextGrid.NET each cell may have own background color. Color may be set by using BackColor property of Cell.
nextGrid1[2, 3].BackColor = Color.Red;
Cell's color may be set dynamically by using CellColoring event.
private void nextGrid1_CellColoring(object sender, CellEventArgs e, bool selected, ref Color cellColor, ref Color bottomGridColor, ref Color rightGridColor) { if (!selected) { if (e.Y % 2 == 0) { cellColor = Color.Cornsilk; // colorize every second row } } }
Please note that CellColoring event occur for inactive cells too. To limit coloring for only active cells write:
if (y < nextGrid1.RowCount) {...
3. Set grid lines color dynamically
Painting horizontal or vertical grid lines may be useful sometime. For example for framing cells, dividing columns and similar. Example:
private void nextGrid1_CellColoring(object sender, CellEventArgs e, bool selected, ref Color cellColor, ref Color bottomGridColor, ref Color rightGridColor) { if (y == nextGrid1.RowCount - 1) { bottomGridColor = Color.Brown; } }
4. Access to the newly added row
It is handy to have access to the last added row.
There are two solutions for that.
4.1. LastAddedRow propertyu
LastAddedRow property is update after methods such as AddRow or InsertRow are called.
nextGrid1.AddRow(); nextGrid1[0, nextGrid1.LastAddedRow].Value = 5; nextGrid1[nextGrid1.LastAddedRow].Height = 32;
4.2. Return value of methods
Methods like LastAddedRows, InsertRow are returning a newly created row object (GridRow) so can be used for immediate access. Example:
nextGrid1.AddRow().Cells[2].Value = "test"; nextGrid1.AddRow().Visible = false;
5. Enable search-as-you-type for column
To enable incremental search-as-you-type feature for grid set Search property of Column to true. Only one column may be "search' column at time.
Searching will be performed at any non-editable column (Editing = false).
6. How to access to a cell
Beside standard this indexer for accessing cells, there is overloaded indexer too.
This indexer accepts 2 Object parameters. Both parameters may be int as in standard this indexer, but they may be CellColumnLocation and CellRowLocation too.
Name | Meaning |
---|---|
First | First column in Columns array. |
Last | Last column in Columns array. |
Selected | Equal to SelectedColumn property. |
Example:
nextGrid1[CellColumnLocation.Selected, 1].Value = "test";
Name | Meaning |
---|---|
First | First row in grid. |
FirstVisible | First visible row in grid. It may differ than First! |
Last | Last row in grid. |
LastVisible | Last visible row in grid. It may differ than Last! |
Selected | Equal to SelectedRow property. |
Example:
nextGrid1[CellColumnLocation.First, CellRowLocation.LastVisible].Value = "test";