Sharing the Code

Programming stuff that might be useful to others

Having checkboxes etc in a .NET CF 2.0 datagrid

DataGrids are really useful for displaying information on PDAs but in .NET CF 2.0 it’s very restrictive. With service pack 1 they’ve added a Paint method so you can add custom controls.

Patch for Visual Studio 2005

Sample project which comes with custom components that you can use in a data grid. There’s more info about the service pack on this blog and some improvements to the code on this blog.

I modified the designer’s generated code so the data grid would use the custom controls but it broke the designer, even with the VS patch installed. So instead I but the code in a method in the non-generated partial class and called the method from the generated InitializeComponent().

So, basically in the designer I dragged across a blank datagrid and in the non-generated part of the class (ItineraryForm.cs) I added my custom column types. The custom datagrid column classes are available as components in the sample project download above which you will have to add to your project.

ItineraryForm.designer.cs (code generated by designer):

[sourcecode language=’c#’]
private void InitializeComponent() {

//add the following line near the end of the method:
CustomInitializeComponent();

//
// ItineraryForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);

}
[/sourcecode]

ItineraryForm.cs (other part of the partial class):

[sourcecode language=’c#’]
private DataGridCustomTextBoxColumn dateColumnStyle;
private DataGridCustomCheckBoxColumn uploadedColumnStyle;

private void CustomInitializeComponent() {
//Date Time Picker
this.dateColumnStyle = new DataGridCustomDateTimePickerColumn();
this.dateColumnStyle.Owner = this.itineraryDataGrid;
this.dateColumnStyle.Format = “”;
this.dateColumnStyle.HeaderText = “Date”;
this.dateColumnStyle.MappingName = “date”;
this.dataGridTableStyle1.GridColumnStyles.Add(this.dateColumnStyle);

//Checkbox
this.uploadedColumnStyle = new DataGridCustomCheckBoxColumn();
this.uploadedColumnStyle.HeaderText = “Uploaded”;
this.uploadedColumnStyle.MappingName = “uploaded”;
this.uploadedColumnStyle.NullText = “”;
this.uploadedColumnStyle.Owner = this.itineraryDataGrid;
this.uploadedColumnStyle.ReadOnly = true;
this.uploadedColumnStyle.Width = 60;
this.dataGridTableStyle1.GridColumnStyles.Add(this.uploadedColumnStyle);
}
[/sourcecode]

2 Responses

RSS Feed
 
achuta

Hi there,

I am also developing something similar to this. But my checkbox (instead of DTP) is not appearing properly.

Can you please send me some very basic code for achieving this?

Thanks and Regards,
achuta

 
Wiliam Renato Bertoncini

i´m from BRAZIL and i don´t speak english very well, but i´ll try.

I’m currently studying the 4th year System of Information Degree at UNIFIL University in Brazil.

I’m developing my thesis about mobile devices (Pocket PC Windows Mobile 6) and I need a datagrid with checkbox column.

Can you help me ???

I appreciate your reply,

Regards,

Wiliam Renato Bertoncini

 

Comments are closed