Tuesday, March 27, 2012

Using custom grids in Client Forms.

Sometimes we need to build our custom grid to display/manipulate different data.
We can use a standart DataGridView control from System.Windows.Forms.dll, but it doesn't match to Pivotal color scheme.
Therefore there is DataGridViewWithStyle pivotal control in CdcSoftware.Ios.UI.dll that looks like a common Pivotal secondary control.

Here is an example how to use it:

1. Add PivotalCustomControlContainer to a client form
2. Write some client code in form client task:

// Get container control
PivotalCustomControlContainer customGridContainer = this.FormControl.GetControlByName("CustomGridContainer") as PivotalCustomControlContainer;

// Declare custom grid properties and columns
DataGridViewWithStyle customGrid = new DataGridViewWithStyle();
customGrid.Dock = DockStyle.Fill;
customGrid.AllowUserToAddRows = false;
customGrid.AllowUserToDeleteRows = false;
customGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
customGrid.Columns.Add(new DataGridViewTextBoxColumn() { Name = "Id", HeaderText = "Id", Visible = false });
customGrid.Columns.Add(new DataGridViewTextBoxColumn() { Name = "Name", HeaderText = "Name", ReadOnly = true });
customGrid.Columns.Add(new DataGridViewTextBoxColumn() { Name = "Age", HeaderText = "Age", ReadOnly = true });

// Add custom grid to the container
customGridContainer.CustomControl = customGrid;

// Populate grid data
this.PopulateGrid(customGrid);

Thats all.

Regards,
Max Shafranski

No comments:

Post a Comment