Hi,
With doing rowspan in the cells of the ultrawingrid in runtime?
(version 2008 v 3)
see the code below:
private void button1_Click(object sender, EventArgs e) { UltraDataSource uds = new UltraDataSource(); int totCols = 20; for (int c = 0; c < totCols; c++) { uds.Band.Columns.Add(c.ToString()); } int totRows = 20; uds.Rows.SetCount(totRows); ultraGrid1.DataSource = uds; this.ultraGrid1.CreationFilter = new ColRowSpan(); ultraGrid1.DisplayLayout.Override.RowSelectorNumberStyle = RowSelectorNumberStyle.VisibleIndex; ultraGrid1.DisplayLayout.Override.RowSizing = RowSizing.AutoFree; ultraGrid1.DisplayLayout.Override.CellMultiLine = Infragistics.Win.DefaultableBoolean.True; ultraGrid1.Rows[0].Cells[0].Value = "Label alfanumérico:"; ultraGrid1.Rows[0].Cells[0].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; ultraGrid1.Rows[0].Cells[0].Appearance.BackColor = SystemColors.Control; Infragistics.Win.ValueList list = new Infragistics.Win.ValueList(); // ultraGrid1.DisplayLayout.ValueLists.Add("Booleano"); list.ValueListItems.Add("SIM", "SIM"); list.ValueListItems.Add("NÃO", "NÃO"); list.ValueListItems.Add("OK", "OK"); ultraGrid1.Rows[1].Cells[0].Value = "DropDownList:"; ultraGrid1.Rows[1].Cells[0].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; ultraGrid1.Rows[1].Cells[1].ValueList = list; ultraGrid1.Rows[1].Cells[1].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; Celula cel = new Celula(); cel.Codigo = 1; cel.Row = 2; cel.Col = 0; cel.ColSpan = 2; cel.Rotulo = "aqui um colspan"; cel.Tipo = "R"; ultraGrid1.Rows[2].Cells[0].Tag = cel; Celula cel1 = new Celula(); cel1.Codigo = 2; cel1.Row = 3; cel1.Col = 0; cel1.RowSpan = 2; cel1.Rotulo = "aqui um rowspan"; cel1.Tipo = "R"; ultraGrid1.Rows[3].Cells[0].Tag = cel1; Infragistics.Win.UIElementViewer.UIElementViewerDialog dl = new Infragistics.Win.UIElementViewer.UIElementViewerDialog(); dl.Show(this); }
public class Celula { private int nrColuna; private int nrLinha; private string inTipo; private decimal comprCol; private decimal alturaLinha; private int colSpan; private int rowSpan; private string rotulo; public Celula() { nrColuna = 0; nrLinha = 0; inTipo = String.Empty; comprCol = 0; alturaLinha = 0; colSpan = 0; rowSpan = 0; rotulo = ""; } int codigo = 0; public int Codigo { get { return codigo; } set { codigo = value; } } public virtual int Col { get { return nrColuna; } set { nrColuna = value; } } public virtual int Row { get { return nrLinha; } set { nrLinha = value; } } public virtual String Tipo { get { return inTipo; } set { inTipo = value; } } public virtual decimal ComprCol { get { return comprCol; } set { comprCol = value; } } public virtual decimal AlturaLinha { get { return alturaLinha; } set { alturaLinha = value; } } public virtual int ColSpan { get { return colSpan; } set { colSpan = value; } } public virtual int RowSpan { get { return rowSpan ; } set { rowSpan = value; } } public virtual String Rotulo { get { return rotulo; } set { if (value == null) rotulo = ""; else rotulo = value; } } }
public class ColRowSpan : Infragistics.Win.IUIElementCreationFilter { // help.infragistics.com/.../Infragistics2.Win.v8.2~Infragistics.Win.UltraControlBase~CreationFilter.html #region Implementation of IUIElementCreationFilter public void AfterCreateChildElements(Infragistics.Win.UIElement parent) { } public bool BeforeCreateChildElements(Infragistics.Win.UIElement parent) { //Declare some variables Infragistics.Win.UltraWinGrid.CellUIElement objCellUIElement; Infragistics.Win.UltraWinGrid.UltraGridCell objCell; Infragistics.Win.UltraWinGrid.UltraGrid grid; if (parent is Infragistics.Win.UltraWinGrid.CellUIElement) { //Get a reference to the cell, and the cells ui element. objCellUIElement = (Infragistics.Win.UltraWinGrid.CellUIElement)parent; objCell = (Infragistics.Win.UltraWinGrid.UltraGridCell)objCellUIElement.GetContext(typeof(Infragistics.Win.UltraWinGrid.UltraGridCell)); grid = (Infragistics.Win.UltraWinGrid.UltraGrid)objCellUIElement.GetContext(typeof(Infragistics.Win.UltraWinGrid.UltraGrid)); int spanWidth = objCell.Width; int spanHeight = objCell.Height; Celula cel = (Celula)objCell.Tag; if (cel != null) { //configura o rotulo if (cel.Tipo.ToUpper() == enTipoElemento.R.ToString()) { objCell.Value = cel.Rotulo; objCell.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.FormattedText; objCell.Appearance.BackColor = SystemColors.ButtonShadow; //SystemColors.Control; } //ColSpan if (cel.ColSpan != 0) { for (int ifor = objCell.Column.Index + 1; ifor < (objCell.Column.Index + cel.ColSpan); ifor++) { Infragistics.Win.UltraWinGrid.UltraGridCell nextCel = objCell.Row.Cells[ifor]; spanWidth += nextCel.Width; // calcula o tamanho do span //Oculta as demais celulas fora do span nextCel.Hidden = true; } objCellUIElement.Rect = new Rectangle(objCellUIElement.Rect.X, objCellUIElement.Rect.Y, spanWidth, objCellUIElement.Rect.Height); } //RowSpan if (cel.RowSpan != 0) { for (int ifor = objCell.Row.Index + 1; ifor < (objCell.Row.Index + cel.RowSpan); ifor++) { spanHeight += grid.Rows[ifor].Height; // calcula o tamanho do span Infragistics.Win.UltraWinGrid.CellUIElement cellUI = (Infragistics.Win.UltraWinGrid.CellUIElement)grid.Rows[ifor].Cells[objCell.Column.Index].GetUIElement(); if (cellUI != null) cellUI.Rect = new Rectangle(0, 0, 0, 0); } objCellUIElement.Rect = new Rectangle(objCellUIElement.Rect.X, objCellUIElement.Rect.Y, objCellUIElement.Rect.Width, spanHeight); } } } //Return false to let the grid know we did not handle the event. return false; } #endregion }
It's really hard to tell anything from a code snippet like this. I'm not sure what you are asking.
Hi Mike I need to do rowspan and colspan in the cells of the grid in execution time with base in the information of my object Celula. In the example code I managed to do Colspan, but I didn't get RowSpan of the cells of the grid. How do I make RowSpan in the cells of the ultragrid? Thanks
I'm still not clear on what you are asking.
What do you mean by "I need a cell covers multiple lines."?
Are you talking about multiple lines within the same row of data? Or are you talking about a cell that covers mutliple rows?
If the former, then you really don't need a CreationFilter at all, you could just set up a RowLayout. It's pretty complicated to do this at run-time, but it can be done with a little understanding how the concept of a GridBagLayout. You just set the properties on the column.RowLayoutColumnInfo like OriginX, OriginY, SpanX, and SpanY.
If it's the latter, then you would have to create a pretty complex CreationFilter for that. If that's the case, I'm not sure it's something I could really assist you with in a forum post or if it's even possible. The implications are quite far-reaching and complex.
It is the latter case, using the CreationFilter.
Thanks.
See picture attached
Okay. As I explained, this will be extremely difficult and complex and there are a lot of unknown factors here.
For one thing,what is the value of this merged cell? There would be two different cells in the actual grid with 2 different data values, so how do you determine what displays in this merged cell?
Merging cells from two rows where the values are not the same doesn't seem to make any sense, so I'm not sure how I can help you with this without knowing what you are trying to do and why.
Hi, The cells do not have different values, will only have value in that cell will be displayed. To facilitate understanding, we consider that there is no data in the grid. Let's say we set the grid layout of the cell formatting, no values. Do not worry about data, think only in the grid layout that will have rowspan and colspan (no data, only formatting the cells). Is there a feature (method or property) that allows the RowSpan is made of cells? I managed to do a colspan, but the same logic did not work in the rowspan.
Thanks