Search Forum
(53671 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


 
Printable Version

Playing With Datagrid
By Tushar A

Introduction

Accessing data has become a major programming task for modern software programming, both for standalone applications and for web-based applications. Microsoft's ADO.NET technology offers a solution to many of the problems associated with data access. Among the important part of ADO.NET ,DATAGRID control holds an important stature. Below is presented an article on DATAGRID and other related classes and how the user can play with them. The versatile DataGrid control displays tabular data and supports selecting, sorting, and editing the data. Each data field is displayed in 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 created above, you have to focus on the TextBox Control that is present in each cell 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.