Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
90
RowSpan in cells
posted

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
    }