Playing With Datagrid
Introduction
Accessing data has become a major programmingtask for modern software programming, both for standalone applicationsand for web-based applications. Microsoft's ADO.NET technology offers asolution to many of the problems associated with data access. Among theimportant part of ADO.NET ,DATAGRID control holds an important stature.Below is presented an article on DATAGRID and other related classes andhow the user can play with them.The versatile DataGrid control displays tabular data and supportsselecting, sorting, and editing the data. Each data field is displayedin a separate column in the order it is stored in the database.
Download Dynamic.cs
Download Controls.cs

dataGrid1.jpg

dataGrid2.jpg

dataGrid3.jpg
* Adding Rows, columns and controls to the DATAGRID dynamically
Refer Dynamic.cs(for source Code) and dataGrid1.jpg for the DataGrid view.
* How to add a check box control to a grid
Refer Controls.cs for source code and dataGrid2.jpg for DataGrid View.
* Focusing a particular cell in the Data Grid
To focus a particular cell in the grid createdabove, you have to focus on the TextBox Control that is present in eachcell of the DataGrid created above.
To take the text box present in the grid cell which u want to focus, Follow the steps followed below:
//Bring the focus to the grid in which the cell is present (where u want
//the focus)
dgdLoad.Focus();
//Create a DataGrid Cell object and take the Cell by passing Row and
//Column number respectively
DataGridCell dgc = new DataGridCell(1,1);
//here it is 2ndrow, 2nd Column
//Make the current cell of the grid as the cell u have taken above i.e.
//the cell where u need the focus to be
dgdLoad.CurrentCell = dgc;
//To take the text Box of the cell where u want the focus to be take
//it from the Table Styles of the grid and in that the column style
//by passing the column number where u wants the focus to be
DataGridTextBoxColumn dgtb = (DataGridTextBoxColumn)dgdLoad.TableStyles[0].GridColumnStyles[2];
//Focus on the text box i.e. in turn on cell where u need the focus
dgtb.TextBox.Focus();
Refer dataGrid3.jpg depicting the above concept.
Refer Dynamic.cs and Controls.cs files for source code.












No comments yet... Be the first to leave a reply!