.Net Compact Framework V2 Service Pack 1 Data Grid control enhancements.
Data Grid control available on Compact Framework is extensively used to represent various data. It is fast as only visible rows are retrieved from data source and relatively easy to use.
However, Compact Framework version of the Data Grid is not as extensible as its desktop counterpart and lacking some key features developers needed to create modern application.
Among most requested features is the ability to format data displayed by Data Grid, check box column availability and inability to use different colors for odd and even rows (even though very complex solution for last one is available here).
Compact framework V2 Service Pack 1 introduces minor, but very useful extensions to address these issues either directly (e.g. data formatting) or by allowing customer to perform custom cell drawings to achieve desired results.
Let's take a look at these additions:
Class Name |
Method or Property |
Functionality |
DataGridColumnStyle |
public virtual PropertyDescriptor PropertyDescriptor { set; get; } |
Property descriptor allows access to this column data in the data source so it could be processed as needed. |
DataGridColumnStyle |
protected internal virtual void Paint(Graphics g,Rectangle bounds,CurrencyManager source,int rowNum,Brush backBrush,Brush foreBrush,bool alignToRight); |
Protected Paint() method is called as cell is drawn. Overriding it allows representing data from data source in any way imaginable. Colors, fonts, formatting, alignment, pictures and more - anything is possible as long as it can be painted. CurrencyManager and row number along with PropertyDescriptor allows fetching data from data source to convert and format the way you want. |
DataGridTextBoxColumn |
public string Format { set; get; } |
Format string to be used to format data in the column. To be used the same way as on desktop or in simple data binding. |
DataGridTextBoxColumn |
public IFormatProvider FormatInfo { set; get; } |
Format provider to be used to format data in the column. To be used the same way as on desktop or in simple data binding. |
Format related properties are very easy to use, they can be set via designers the same way it's done on the desktop.
Overriding Paint() is not hard as well, but requires some coding. To illustrate how that can be done, I've created small sample which shows sample data in several custom columns.
To use the sample, please download it here, rename the file so it has .msi extension and install it on to your PC. You would also need .Net Compact Framework V2 SP1 installed, currently available in Beta here.
After sample is installed, it is accessible via Start Menu. Please make sure to rebuild the solution before browsing the code otherwise Visual Studio would be unable to find the assembly with custom Table Styles and would show errors. Enjoy.
[Author: Ilya Tumanov]
Comments
Anonymous
April 25, 2006
Скоро выйдет финальный SP1, а пока список улучшений, пояснение по части DataGridAnonymous
April 27, 2006
 
Software / Hardware 
ActiveSync 4.2 Beta Preview has been released
SlingPlayer Mobile...Anonymous
March 16, 2007
前段时间发布了Beta版,还没有来的及试用,现在终于发布了正式版。Anonymous
November 10, 2007
One of the questions that has recently come up on the .Net CF MSDN forums was on how to create a customAnonymous
November 10, 2007
One of the questions that has recently come up on the .Net CF MSDN forums was on how to create a customAnonymous
November 10, 2007
PingBack from http://msdnrss.thecoderblogs.com/2007/11/10/datagrid-with-a-custom-header-and-selection/Anonymous
November 22, 2008
PingBack from http://blog.markhorgan.com/?p=35Anonymous
January 18, 2009
PingBack from http://www.keyongtech.com/1802909-image-in-cell-of-datagridAnonymous
January 20, 2009
PingBack from http://www.hilpers.com/265625-listview-details-rowhighAnonymous
June 02, 2009
PingBack from http://portablegreenhousesite.info/story.php?id=33298