Exemplo n.º 1
0
        private void _flex_SetupColumns(object sender, EventArgs e)
        {
            // get grid that was just bound
            C1FlexDataTree grid = sender as C1FlexDataTree;

            if (grid == null || grid.DataSource == null)
            {
                return;
            }

            // get source DataTable
            CurrencyManager cm = (CurrencyManager)BindingContext[grid.DataSource, grid.DataMember];
            DataTable       dt = ((DataView)cm.List).Table;

            // apply custom column order, captions, format
            string[] columns = dt.ExtendedProperties["ShowColumns"] as string[];
            if (columns != null)
            {
                SetupColumns(grid, columns);
            }

            // apply custom data maps
            foreach (Column gridColumn in grid.Cols)
            {
                DataColumn dataColumn = dt.Columns[gridColumn.Name];
                if (dataColumn == null)
                {
                    continue;
                }
                gridColumn.DataMap = dataColumn.ExtendedProperties["DataMap"] as IDictionary;
                if (gridColumn.DataMap != null)
                {
                    gridColumn.TextAlign = TextAlignEnum.LeftCenter;
                }
            }

            // all done, autosize to show mapped data
            if (grid.AutoResize)
            {
                grid.AutoSizeCols(12);
            }
        }
Exemplo n.º 2
0
        void SetupColumns(C1FlexDataTree grid, string[] columns)
        {
            // initialize column position
            int position = grid.Cols.Fixed;

            // apply column information
            foreach (string s in columns)
            {
                // split column info (name, caption, format)
                string[] columnInfo = s.Split(',');

                // move column to proper position based on its name
                Column column = grid.Cols[columnInfo[0].Trim()];
                if (column != null)
                {
                    column.Move(position);
                    position++;

                    // apply caption
                    if (columnInfo.Length > 1)
                    {
                        column.Caption = columnInfo[1].Trim();
                    }

                    // apply format
                    if (columnInfo.Length > 2)
                    {
                        column.Format = columnInfo[2].Trim();
                    }
                }
            }

            // hide all other columns
            for (int i = position; i < grid.Cols.Count; i++)
            {
                grid.Cols[i].Visible = false;
            }
        }