The first thing I do is register the grid’s “InitializeLayout” event in the form. This can be done with the form wizards. Basically this allows you to do something with that event.
It will look something like this for registration:
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
this.grdInput.InitializeLayout += new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.grdInput_InitializeLayout);
///More stuff below
}
Deregistration:
public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal
this.grdInput.InitializeLayout -= new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.grdInput_InitializeLayout);
}
And it will include a method to then write code inside of.
private void grdInput_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs args)
{
// ** Place Event Handling Code Here **
grdInput.EpiAllowPaste = true;
grdInput.EpiAllowPasteInsert = true;
grdInput.InsertNewRowAfterLastRow = false;
}
With that method in place and the event registered, you can then interact with it.
Here is a different example of some manipulation including adding columns and resizing stuff. Of note, the “Perform Auto Resize Columns” is particularly handy if you want it to self-size with the data.
private void grdSigners_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs args)
{
// ** Place Event Handling Code Here **
//add mutually exclusive boolean to the grid to select primary signer
//args.Layout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.False;
args.Layout.Override.MinRowHeight = 20;
args.Layout.Override.DefaultRowHeight = 20;
args.Layout.Bands[0].Columns.Add("Primary");
args.Layout.Bands[0].Columns["Primary"].DataType = typeof(bool);
args.Layout.Bands[0].Columns["Primary"].Header.VisiblePosition = 0;
//args.Layout.Bands[0].Columns["Primary"].EditorComponent = this.grdSigners;
args.Layout.Bands[0].Columns["Primary"].Width = 16;
args.Layout.Bands[0].Columns["Primary"].MinWidth = 16;
args.Layout.Bands[0].Columns["Primary"].MaxWidth = 16;
grdSigners.DisplayLayout.PerformAutoResizeColumns(false, Infragistics.Win.UltraWinGrid.PerformAutoSizeType.VisibleRows);
}
Does that help spur anything?
Also, the InitializeLayout event is just to get it set up. To have it interactively resize based on other events, it can be helpful to register different events, such as “AfterLayoutChange” to call the PerformAutoResizeColumns method as seen in these examples below:
private void grdCCs_AfterSelectChange(object sender, Infragistics.Win.UltraWinGrid.AfterSelectChangeEventArgs args)
{
// ** Place Event Handling Code Here **
grdCCs.DisplayLayout.PerformAutoResizeColumns(false, Infragistics.Win.UltraWinGrid.PerformAutoSizeType.VisibleRows);
}
private void grdCCs_AfterCellUpdate(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs args)
{
// ** Place Event Handling Code Here **
grdCCs.DisplayLayout.PerformAutoResizeColumns(false, Infragistics.Win.UltraWinGrid.PerformAutoSizeType.VisibleRows);
}
private void grdSigners_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs args)
{
//Allows for only 1 row to be selected as "Primary"
foreach(var item in grdSigners.Rows)
{
if(args.Cell.Row.Index != item.Index)
{
item.Cells["Primary"].Value = false;
item.CancelUpdate();
}
}
}