Data Binding with Windows Forms

Data Binding with Windows FormsData binding is a powerful capability that has finally matured in Windows Forms 2.0 through the capabilities in the .NET Framework classes, combined with the rich designer support provided by Visual Studio 2005. By using data binding properly, you can save yourself from writing a lot of unnecessary code, provide your users a rich interactive experience for working with data that functions well, and produce code that is easy to maintain. To get it correctly across a variety of use cases, you need to know more than how to set a few properties on controls. You need to understand what is going on under the hood, especially if you want to support complex scenarios that require going beyond the basic capabilities of the data binding components in the .NET Framework.


The DataGridView control is a very powerful, flexible, and yet easy to use control for presenting tabular data. It is far more capable than the DataGrid control and is easier to customize and interact with. You can let the grid do all the work of presenting data in tabular form by setting the data binding properties on the control appropriately. You can also take explicit control of presenting data in the grid through the new features of unbound columns and virtual mode. Unbound columns allow you to formulate the contents of the cell as the cells are being added to the grid. Virtual mode gives you a higher degree of control by allowing you to wait until a cell is actually being displayed to provide the value it will contain. You can make the grid act like a spreadsheet where the focus for interaction and presentation is at the cell level, instead of at the row or column level. You can control the formatting and layout of the grid with fine-grained precision simply by setting a few properties on the control. Finally, you can plug in a number of pre-defined column and cell control types, or provide your own custom controls, and you can even mix different control types within different cells in the same row or column. Figure 6-1 shows an example of a DataGridView control in action with some of the key visual features highlighted. You can see that the grid picks up the visual styles of Windows XP like many of the Windows Forms controls in .NET 2.0. The grid is composed of columns and rows, and the intersection of a column and a row is a cell. The cell is the basic unit of presentation within the grid, and is highly customizable in appearance and behavior through the properties and events exposed by the grid. There are header cells for the rows and columns that can be used to maintain the context of the data presented in the grid. These header cells can contain graphical glyphs to indicate different modes or functions of the grid, such as sorting, editing, new rows, and selection. The grid can contain cells of many different types, and can even mix different cell types in the same column if the grid is not data bound.

Website: searchsqlserver.techtarget.com | Filesize: 916kb
No of Page(s): 48
Click here to download Data Binding with Windows Forms.

Related Tutorial

Tags: , ,

Comments

Leave a Reply