Example #1
0
        public int Compare(C1.WPF.FlexGrid.Row x, C1.WPF.FlexGrid.Row y)
        {
            var v1 = x[_col];
            var v2 = y[_col];

            // compare values
            int cmp = 0;

            if (v1 == null && v2 != null)
            {
                cmp = -1;
            }
            else if (v1 != null && v2 == null)
            {
                cmp = +1;
            }
            else if (v1 is IComparable && v2 is IComparable)
            {
                cmp = ((IComparable)v1).CompareTo(v2);
            }

            // honor sort direction
            if (_sortDirection == ListSortDirection.Descending)
            {
                cmp = -cmp;
            }

            // return result
            return(cmp);
        }
        public MainWindow()
        {
            InitializeComponent();

            var flex = new C1FlexGrid();
            flex.CellFactory = new ConditionalFormattingFactory();
            LayoutRoot.Children.Add(flex);

            var list = Product.GetProducts(100);

            foreach (var pi in typeof(Product).GetProperties())
            {
                var c = new Column();
                c.Header = pi.Name;
                c.DataType = pi.PropertyType;
                if (pi.PropertyType == typeof(double))
                {
                    c.Format = "n0";
                }
                flex.Columns.Add(c);
            }

            foreach (var p in list)
            {
                var r = new Row();
                flex.Rows.Add(r);
                foreach (var c in flex.Columns)
                {
                    var pi = typeof(Product).GetProperty(c.Header);
                    r[c] = pi.GetValue(p, null);
                }
            }
        }
 void SetData(Row row, string content)
 {
     var items = content.Split('\t');
     for (int i = 0; i < items.Length; i++)
     {
         row[i] = items[i];
     }
 }
 // add a new row to the grid, with an editor of the specified type
 void AddRow(Type cellType)
 {
     var r = new Row();
     r.Tag = cellType;
     _flex.Rows.Add(r);
     _flex[r.Index, "Row#"] = r.Index;
     _flex[r.Index, "Cell Type"] = cellType.Name;
 }
        public MainWindow()
        {
            InitializeComponent();

            #region BoundGrid
            // populate bound grid
            var products = Product.GetProducts(250);
            var view = new ListCollectionView(products);
            _flexBound.ItemsSource = view;

            // add a column footer row to the bound grid
            AddColumnFooter(_flexBound);

            // show aggregate values in subtotal cell
            foreach (var colName in "Price,Cost,Weight,Volume".Split(','))
            {
                var c = _flexBound.Columns[colName];
                c.GroupAggregate = C1.WPF.FlexGrid.Aggregate.Sum;

            }

            #endregion

            #region Unbound
            //populate unbound grid
            AddColumn("Name", typeof(string), null);
            AddColumn("Color", typeof(string), null);
            AddColumn("Price", typeof(double), "n2");
            AddColumn("Cost", typeof(double), "n2");
            AddColumn("Weight", typeof(double), "n2");
            AddColumn("Volume", typeof(double), "n2");
            AddColumn("Discontinued", typeof(bool), null);
            AddColumn("Rating", typeof(int), "n2");
            foreach (var p in products)
            {
                var row = new C1.WPF.FlexGrid.Row();
                _flexUnbound.Rows.Add(row);
                row["Name"] = p.Name;
                row["Color"] = p.Color;
                row["Price"] = p.Price;
                row["Cost"] = p.Cost;
                row["Weight"] = p.Weight;
                row["Volume"] = p.Volume;
                row["Discontinued"] = p.Discontinued;
                row["Rating"] = p.Rating;
            }

            // add a column footer row to the unbound grid
            AddColumnFooter(_flexUnbound);

            // show aggregate values in subtotal cell
            foreach (var colName in "Price,Cost,Weight,Volume".Split(','))
            {
                var c = _flexUnbound.Columns[colName];
                c.GroupAggregate = C1.WPF.FlexGrid.Aggregate.Sum;
            }
            #endregion
        }
        public MainWindow()
        {
            InitializeComponent();

            #region BoundGrid
            // populate bound grid
            var products = Product.GetProducts(250);
            var view     = new ListCollectionView(products);
            _flexBound.ItemsSource = view;

            // add a column footer row to the bound grid
            AddColumnFooter(_flexBound);

            // show aggregate values in subtotal cell
            foreach (var colName in "Price,Cost,Weight,Volume".Split(','))
            {
                var c = _flexBound.Columns[colName];
                c.GroupAggregate = C1.WPF.FlexGrid.Aggregate.Sum;
            }

            #endregion

            #region Unbound
            //populate unbound grid
            AddColumn("Name", typeof(string), null);
            AddColumn("Color", typeof(string), null);
            AddColumn("Price", typeof(double), "n2");
            AddColumn("Cost", typeof(double), "n2");
            AddColumn("Weight", typeof(double), "n2");
            AddColumn("Volume", typeof(double), "n2");
            AddColumn("Discontinued", typeof(bool), null);
            AddColumn("Rating", typeof(int), "n2");
            foreach (var p in products)
            {
                var row = new C1.WPF.FlexGrid.Row();
                _flexUnbound.Rows.Add(row);
                row["Name"]         = p.Name;
                row["Color"]        = p.Color;
                row["Price"]        = p.Price;
                row["Cost"]         = p.Cost;
                row["Weight"]       = p.Weight;
                row["Volume"]       = p.Volume;
                row["Discontinued"] = p.Discontinued;
                row["Rating"]       = p.Rating;
            }

            // add a column footer row to the unbound grid
            AddColumnFooter(_flexUnbound);

            // show aggregate values in subtotal cell
            foreach (var colName in "Price,Cost,Weight,Volume".Split(','))
            {
                var c = _flexUnbound.Columns[colName];
                c.GroupAggregate = C1.WPF.FlexGrid.Aggregate.Sum;
            }
            #endregion
        }
Example #7
0
 internal Binding GetEditBinding(Row row)
 {
     if (Binding != null)
     {
         return Binding;
     }
     if (_fakeBinding == null)
     {
         Binding binding = new Binding();
         binding.Path = new PropertyPath("Tag");
         _fakeBinding = binding;
         _fakeBinding.Mode = BindingMode.TwoWay;
         _fakeBinding.Converter = new ColumnValueConverter();
         _fakeBinding.ConverterParameter = this;
         _fakeBinding.ConverterCulture = row.Grid.GetCultureInfo();
         _fakeBindingSource = new Line();
         _fakeBinding.Source = _fakeBindingSource;
     }
     _fakeBindingSource.Tag = row[this];
     return _fakeBinding;
 }
Example #8
0
 private static Brush GetForegroundBrush(C1FlexGrid grid, Row r, Brush defBrush)
 {
     Brush brush = r.Foreground;
     if (r is GroupRow && brush == null)
     {
         brush = grid.GroupRowForeground;
     }
     if (brush == null)
     {
         return defBrush;
     }
     return brush;
 }
Example #9
0
 private static bool AlignRight(Row r, Column c, Type t)
 {
     if (r is GroupRow && c.Grid != null && c.Index <= c.Grid.Columns.FirstVisibleIndex)
     {
         return false;
     }
     if (t.GetNonNullableType().IsNumeric())
     {
         ColumnValueConverter converter = c.ValueConverter as ColumnValueConverter;
         if (converter == null || converter.Values == null)
         {
             return true;
         }
     }
     return false;
 }
Example #10
0
 /// <summary>
 ///     Gets a value that determines whether a cell should be included in the aggregates
 ///     calculated with the
 ///     <see cref="M:C1.WPF.FlexGrid.C1FlexGrid.GetAggregate(C1.WPF.FlexGrid.Aggregate,C1.WPF.FlexGrid.CellRange)" />
 ///     method.
 /// </summary>
 /// <param name="row">
 ///     <see cref="T:C1.WPF.FlexGrid.Row" /> that contains the cell to be included in the aggregate.
 /// </param>
 /// <param name="col">
 ///     <see cref="T:C1.WPF.FlexGrid.Column" /> that contains the cell to be included in the aggregate.
 /// </param>
 /// <returns>True if the cell should be included in the aggregate calculation, false otherwise.</returns>
 public virtual bool IncludeInAggregate(Row row, Column col)
 {
     if (row is NewRowTemplate)
     {
         return false;
     }
     GroupRow groupRow = row as GroupRow;
     bool flag = (row.GridPanel == null || row.GridPanel.CellType == CellType.Cell);
     if (_piChildItems == null)
     {
         if (!flag)
         {
             return false;
         }
         return groupRow == null;
     }
     if (!flag)
     {
         return false;
     }
     if (groupRow == null)
     {
         return true;
     }
     return groupRow.Level == 0;
 }
        private void FillRowHeaders(string[] rowHeaders, AUGrid c1fgrid)
        {
            bool isrowheaderchecked = true;// rowheaderscheck.IsChecked == true ? true : false;
            //creating row headers
            string[,] rowheadersdata = new string[rowHeaders.Length, 1];
            ////creating data
            for (int r = 0; r < rowheadersdata.GetLength(0); r++)
            {
                for (int c = 0; c < rowheadersdata.GetLength(1); c++)
                {
                    rowheadersdata[r, c] = rowHeaders[r];
                }
            }
            //create & fill row headers
            bool fillrowheaders = isrowheaderchecked;
            if (fillrowheaders)
            {
                var FGrowheaders = c1fgrid.RowHeaders;
                FGrowheaders.Columns[0].AllowMerging = true;
                FGrowheaders.Columns[0].VerticalAlignment = VerticalAlignment.Top;
                FGrowheaders.Columns[0].Width = new GridLength(70);

                for (int i = FGrowheaders.Columns.Count; i < rowheadersdata.GetLength(1); i++)
                {
                    C1.WPF.FlexGrid.Column col = new C1.WPF.FlexGrid.Column();
                    col.AllowMerging = true;
                    col.VerticalAlignment = VerticalAlignment.Top;
                    col.Width = new GridLength(70);
                    FGrowheaders.Columns.Add(col);
                }

                for (int i = FGrowheaders.Rows.Count; i < rowheadersdata.GetLength(0); i++)
                {
                    C1.WPF.FlexGrid.Row row = new C1.WPF.FlexGrid.Row();
                    row.AllowMerging = true;
                    FGrowheaders.Rows.Add(row);
                }

                //fill row headers
                for (int i = 0; i < rowheadersdata.GetLength(0); i++)
                    for (int j = 0; j < rowheadersdata.GetLength(1); j++)
                    {
                        if (rowheadersdata[i, j] != null && rowheadersdata[i, j].Trim().Equals(".-."))
                            FGrowheaders[i, j] = "";//14Jul2014 filling empty header
                        else
                            FGrowheaders[i, j] = rowheadersdata[i, j];
                    }
            }
        }
Example #12
0
 public SongCell(Row row)
     : base(row)
 {
 }
Example #13
0
        public NodeCell(Row row)
            : base(row)
        {
            // create collapsed/expanded images
            if (_bmpExpanded == null)
            {
                _bmpExpanded = ImageCell.GetImageSource("Expanded.png");
                _bmpCollapsed = ImageCell.GetImageSource("Collapsed.png");
            }

            // store reference to row
            _gr = row as GroupRow;

            // initialize collapsed/expanded image
            _nodeImage = new Image();
            _nodeImage.Source = _gr.IsCollapsed ? _bmpCollapsed : _bmpExpanded;
            _nodeImage.Width = _nodeImage.Height = 9;
            _nodeImage.VerticalAlignment = VerticalAlignment.Center;
            _nodeImage.Stretch = Stretch.None;
            _nodeImage.MouseLeftButtonDown += img_MouseLeftButtonDown;
            _nodeImage.MouseEnter += img_MouseEnter;
            _nodeImage.MouseLeave += img_MouseLeave;
            _nodeImage.Opacity = ALPHA;
            Children.Insert(0, _nodeImage);

            // make text bold
            TextBlock.FontWeight = FontWeights.Bold;
        }
Example #14
0
        void AddPersonToGrid(Person p, C1FlexGrid flex, int level)
        {
            // create a row for this person
            Row row;
            if (p.Children.Count > 0 || true)
            {
                var gr = new GroupRow();
                gr.Level = level;
                row = gr;
            }
            else
            {
                row = new Row();
            }
            row.DataItem = p;

            // add this person to the grid
            flex.Rows.Add(row);

            // and add any children
            foreach (var child in p.Children)
            {
                AddPersonToGrid(child, flex, level + 1);
            }
        }
 bool HasVisibleChildren(Row r)
 {
     var gr = r as GroupRow;
     if (gr != null && r.Grid != null)
     {
         var rg = gr.GetCellRange();
         var rows = r.Grid.Rows;
         for (int i = rg.TopRow; i <= rg.BottomRow; i++)
         {
             var row = rows[i];
             if (row != gr && row.Visible)
             {
                 return true;
             }
         }
     }
     return false;
 }
        // gets an image to represents a node
        Image GetNodeImage(Row r, NodeImage nodeImage)
        {
            // load bitmaps (once)
            if (_bmpCollapsed == null)
            {
                _bmpCollapsed = LoadBitmap("Collapsed.png");
                _bmpExpandedAbove = LoadBitmap("ExpandedAbove.png");
                _bmpExpandedBelow = LoadBitmap("ExpandedBelow.png");
                _bmpConnector = LoadBitmap("Connector.png");
                _bmpTerminalAbove = LoadBitmap("TerminalAbove.png");
                _bmpTerminalBelow = LoadBitmap("TerminalBelow.png");
                _bmpNoChildren = LoadBitmap("NoChildren.png");
            }

            // get image source
            ImageSource src = null;
            var above = r.Grid.GroupRowPosition == GroupRowPosition.AboveData;
            switch (nodeImage)
            {
                case NodeImage.Collapsed:
                    if (HasVisibleChildren(r))
                    {
                        src = _bmpCollapsed;
                    }
                    break;
                case NodeImage.Expanded:
                    if (HasVisibleChildren(r))
                    {
                        src = above ? _bmpExpandedAbove : _bmpExpandedBelow;
                    }
                    break;
                case NodeImage.Connector:
                    src = _bmpConnector;
                    break;
                case NodeImage.Terminal:
                    src = above ? _bmpTerminalAbove : _bmpTerminalBelow;
                    break;
            }

            // no source? we're done
            if (src == null)
            {
                return null;
            }

            // create image element
            var img = new Image();
            img.Source = src;
            img.Stretch = Stretch.None;
            img.VerticalAlignment = VerticalAlignment.Center;
            img.HorizontalAlignment = HorizontalAlignment.Center;
            img.Tag = r;

            // assign source
            switch (nodeImage)
            {
                case NodeImage.Collapsed:
                case NodeImage.Expanded:
                    img.MouseLeftButtonDown += img_MouseLeftButtonDown;
                    break;
            }

            // done
            return img;
        }
        // creates a grid element with images to represent a grid node
        Grid CreateCellGrid(Row r, int level, double indent, NodeImage nodeImage)
        {
            // create grid
            var g = new Grid();

            // add columns for images and content
            bool above = r.Grid.GroupRowPosition == GroupRowPosition.AboveData;

            // create elements for each level
            for (int i = 0; i < level + 1; i++)
            {
                // add images to the grid
                if (i <= level)
                {
                    // select image to display in this part of the cell
                    var ni = i == level ? nodeImage : NodeImage.Connector;
                    if (ni == NodeImage.Connector)
                    {
                        var index = r.Index;
                        var rows = r.Grid.Rows;

                        // find next group row to determine the image to display
                        int next = index;
                        if (above)
                        {
                            // look for next group below this one
                            for (next = index + 1; next < rows.Count; next++)
                            {
                                if (rows[next].IsVisible)
                                {
                                    var gr = rows[next] as GroupRow;
                                    if (gr != null && gr.Level <= i)
                                    {
                                        ni = NodeImage.Terminal;
                                    }
                                    break;
                                }
                            }
                            if (next == rows.Count)
                            {
                                ni = NodeImage.Terminal;
                            }
                        }
                        else
                        {
                            // look for next group above this one
                            for (next = index - 1; next > -1; next--)
                            {
                                if (rows[next].IsVisible)
                                {
                                    var gr = rows[next] as GroupRow;
                                    if (gr != null && gr.Level <= i)
                                    {
                                        ni = NodeImage.Terminal;
                                    }
                                    break;
                                }
                            }
                            if (next <= 0)
                            {
                                ni = NodeImage.Terminal;
                            }
                        }
                    }

                    // add image
                    var img = GetNodeImage(r, ni);
                    if (img != null)
                    {
                        var cd = new ColumnDefinition();
                        cd.Width = new GridLength(indent);
                        g.ColumnDefinitions.Add(cd);
                        img.SetValue(Grid.ColumnProperty, i);
                        g.Children.Add(img);
                    }
                }
            }

            // and add a cell for the content
            g.ColumnDefinitions.Add(new ColumnDefinition());

            // done
            return g;
        }
Example #18
0
        //Draw and Fill Grid based on values sent in properties above
        public void DrawFillFlexgrid()
        {
            //string[,] ColHdrArr = new string[4, 7] { {"Test Value = 1", "Test Value = 1", "Test Value = 1","Test Value = 1","Test Value = 1","Test Value = 1", "Total"},
            //                                {"t", "df", "Sig.(2-tailed)", "Mean Diff", "Confidence : 0.95", "Confidence : 0.95", "Total"},
            //                                {"t", "df", "Sig.(2-tailed)", "Mean Diff", "Lower", "Upper", "Total"},
            //                                {"Total", "Total", "Total", "Total", "Total", "Total", "Total"}
            //};

            //string[,] RowHdrArr = new string[8, 5]{ {"A", "M", "S", "S1","Total"},
            //                                        {"A", "M", "S", "S2","Total"},
            //                                        {"A", "M", "S", "S3","Total"},
            //                                        {"A", "F", "S", "S1","Total"},
            //                                        {"A", "F", "S", "S2","Total"},
            //                                        {"A", "F", "S", "S3","Total"},
            //                                        {"A", "F", "S", "S4","Total"},
            //                                        {"Total", "Total", "Total", "Total","Total"}
            //};

            //////// FILLING STRING ARRAY DATA ///// 7 row from rowhdr count, 6 from colhdr count
            //string[,] dataArr = new string[7, 6] {  {"a", "b", "c", "d", "e", "f"},
            //                                        {"a", "b", "c", "d", "e", "f"},
            //                                        {"a", "b", "c", "d", "e", "f"},
            //                                        {"a", "b", "c", "d", "e", "f"},
            //                                        {"a", "b", "c", "d", "e", "f"},
            //                                        {"a", "b", "c", "d", "e", "f"},
            //                                        {"a", "b", "c", "d", "e", "f"}
            //};

            //values set in properties first then those values are used here to generate FlexGrid
            string[,] ColHdrArr = ColHeaders;
            string[,] RowHdrArr = RowHeaders;
            string[,] dataArr   = GridData;

            //Create Headers
            AUGrid c1FlexGrid1 = this.Grid;

            ///////////// merge and sizing /////
            c1FlexGrid1.AllowMerging = AllowMerging.ColumnHeaders | AllowMerging.RowHeaders;
            c1FlexGrid1.AllowSorting = true;

            var rowheaders = c1FlexGrid1.RowHeaders;
            var colheaders = c1FlexGrid1.ColumnHeaders;


            colheaders.Rows[0].AllowMerging        = true;
            colheaders.Rows[0].HorizontalAlignment = HorizontalAlignment.Center;

            rowheaders.Columns[0].AllowMerging      = true;
            rowheaders.Columns[0].VerticalAlignment = VerticalAlignment.Top;


            /////////////Col Headers//////////
            for (int i = colheaders.Rows.Count; i < ColHdrArr.GetLength(0); i++) //datamatrix.GetLength(0)
            {
                C1.WPF.FlexGrid.Row row = new C1.WPF.FlexGrid.Row();
                colheaders.Rows.Add(row);
                row.AllowMerging        = true;
                row.HorizontalAlignment = HorizontalAlignment.Center;
            }
            for (int i = colheaders.Columns.Count; i < ColHdrArr.GetLength(1); i++) // creating col headers
            {
                C1.WPF.FlexGrid.Column col = new C1.WPF.FlexGrid.Column();
                colheaders.Columns.Add(col);
                col.AllowMerging = true;
            }

            //fill col headers
            bool colheadersexists = ((ColHdrArr != null) && (ColHdrArr.Length >= dataArr.GetLength(1))) ? true : false; //length should be same

            for (int i = 0; i < ColHdrArr.GetLength(0); i++)                                                            //datamatrix.GetLength(0)
            {
                for (int j = 0; j < ColHdrArr.GetLength(1); j++)
                {
                    if (colheadersexists)
                    {
                        colheaders[i, j] = ColHdrArr[i, j];
                    }
                    else
                    {
                        colheaders[i, j] = j + 1;//colheadermatrix[i, j];
                    }
                }
            }

            /////////////Row Headers///////////
            for (int i = rowheaders.Columns.Count; i < RowHdrArr.GetLength(1); i++) //datamatrix.GetLength(1)
            {
                C1.WPF.FlexGrid.Column col = new C1.WPF.FlexGrid.Column();
                col.AllowMerging      = true;
                col.VerticalAlignment = VerticalAlignment.Top;
                rowheaders.Columns.Add(col);
            }

            for (int i = rowheaders.Rows.Count; i < RowHdrArr.GetLength(0); i++)
            {
                C1.WPF.FlexGrid.Row row = new C1.WPF.FlexGrid.Row();
                rowheaders.Rows.Add(row);
                row.AllowMerging = true;
            }

            //fill row headers
            bool rowheadersexists = ((RowHdrArr != null) && (RowHdrArr.Length >= dataArr.GetLength(0))) ? true : false;//length should be same

            for (int i = 0; i < RowHdrArr.GetLength(0); i++)
            {
                for (int j = 0; j < RowHdrArr.GetLength(1); j++)  //datamatrix.GetLength(1)
                {
                    if (rowheadersexists)
                    {
                        rowheaders[i, j] = RowHdrArr[i, j];
                    }
                    else
                    {
                        rowheaders[i, j] = i + 1;//colheadermatrix[i, j];
                    }
                }
            }


            bool isemptyrow;

            for (int rw = 0; rw < dataArr.GetLength(0); rw++)
            {
                isemptyrow = true;//assuming row is empty
                for (int c = 0; c < dataArr.GetLength(1); c++)
                {
                    if (dataArr[rw, c] != null && dataArr[rw, c].Trim().Length > 0)
                    {
                        c1FlexGrid1[rw, c] = dataArr[rw, c];
                        isemptyrow         = false;// if it has atleast one column filled then row is not empty
                    }
                }
                //// hide or remove empty row////
                if (isemptyrow)
                {
                    c1FlexGrid1.Rows[rw].Visible = false;
                }
            }
        }
Example #19
0
        /// using the xml doc xd [ <html>...</html> ] create row/col headers and datamatrix
        /// for the referenced flexgrid and then populate the grid
        public void html2flex(XmlDocument xd, AUGrid c1FlexGrid1)
        {
            RefreshAPAConfig();
            //AUXGrid xgrid = (AUXGrid)c1FlexGrid1.Tag;
            #region create Row, Col header and data matrix
            string[,] colheadermatrix = null;
            string[,] rowheadermatrix = null;
            string[,] datamatrix      = null;
            {
                /////////generate col header////////
                #region
                XmlNode thead = xd.SelectSingleNode("/html/body/table/thead");
                if (thead == null)
                {
                }
                int colheaderrows = thead.ChildNodes.Count; //no. of rows in colheader
                int colheadercols = 0;                      //no.cols in each row of colheader
                //////No of Cols in Colheader///////////
                XmlNode tr = xd.SelectSingleNode("/html/body/table/thead/tr");
                foreach (XmlNode th in tr.ChildNodes)
                {
                    //if (th.InnerText.Trim().Length > 0) colheadercols++;
                    colheadercols++;
                }
                if (colheadercols > 0 && colheaderrows > 0)
                {
                    ///////Colheader Matrix//////////
                    colheadermatrix = new string[colheaderrows, colheadercols];
                    ////fill Matrix////////
                    int row = 0, col;
                    foreach (XmlNode trr in thead.ChildNodes)// <tr>
                    {
                        col = 0;
                        foreach (XmlNode th in trr.ChildNodes)
                        {
                            if (th.InnerText.Trim().Length > 0)
                            {
                                colheadermatrix[row, col++] = th.InnerText.Trim();
                            }
                        }
                        row++;
                    }
                }
                #endregion
                /////////generate col header and data////////
                #region
                XmlNode tbody = xd.SelectSingleNode("/html/body/table/tbody");
                if (tbody == null)
                {
                }
                int rowheaderrows = tbody.ChildNodes.Count; //no. of rows in rowheader. Also, No of data rows
                int rowheadercols = 0;                      //no.cols in each row of rowheader
                int datacols      = 0;                      //no. of data columns
                //////No of Cols in Rowheader and data////////
                XmlNode tr2 = xd.SelectSingleNode("/html/body/table/tbody/tr");
                if (tr2 != null)
                {
                    foreach (XmlNode td in tr2.ChildNodes)//<td>
                    {
                        XmlAttributeCollection xac = td.Attributes;
                        foreach (XmlAttribute xa in xac)
                        {
                            if (xa.Name.Equals("class") && xa.Value.Equals("h")) //row header cols
                            {
                                rowheadercols++;
                            }
                            else if (xa.Name.Equals("class") && xa.Value.Equals("c"))// data col
                            {
                                datacols++;
                            }
                            else
                            {
                            }
                        }
                    }
                }

                if (rowheadercols > 0 && rowheaderrows > 0)
                {
                    /////// Rowheader/Data Matrix//////////
                    rowheadermatrix = new string[rowheaderrows, rowheadercols];
                    datamatrix      = new string[rowheaderrows, datacols];
                    ////fill Row header Matrix and Data Matrix////////
                    int row2 = 0, rhcol, dtcol;
                    foreach (XmlNode trr in tbody.ChildNodes)// <tr>
                    {
                        rhcol = 0; dtcol = 0;
                        foreach (XmlNode td in trr.ChildNodes)
                        {
                            if (rhcol < rowheadercols) // row header col of a row
                            {
                                rowheadermatrix[row2, rhcol++] = td.InnerText.Trim();
                            }
                            else
                            {
                                datamatrix[row2, dtcol++] = td.InnerText.Trim();
                            }
                        }
                        row2++;
                    }
                }
                #endregion
            }
            #endregion

            #region populating C1flexGrid
            ////// Populate Row/Col Headers and Data //////

            //// creating hreaders ////

            ///////////// merge and sizing /////
            c1FlexGrid1.AllowMerging = AllowMerging.ColumnHeaders | AllowMerging.RowHeaders;
            c1FlexGrid1.AllowSorting = true;

            //trying to fix the size of the grid so that rendering does not take much time calculating these
            c1FlexGrid1.MaxHeight = 800;// NoOfRows* EachRowHeight;
            c1FlexGrid1.MaxWidth  = 1000;

            var rowheaders = c1FlexGrid1.RowHeaders;
            var colheaders = c1FlexGrid1.ColumnHeaders;

            colheaders.Rows[0].AllowMerging        = true;
            colheaders.Rows[0].HorizontalAlignment = HorizontalAlignment.Center;

            rowheaders.Columns[0].AllowMerging      = true;
            rowheaders.Columns[0].VerticalAlignment = VerticalAlignment.Top;


            if (APA)
            {
                c1FlexGrid1.GridLinesVisibility    = GridLinesVisibility.None;
                c1FlexGrid1.HeaderGridLinesBrush   = Brushes.White;
                c1FlexGrid1.ColumnHeaderBackground = Brushes.White;
                c1FlexGrid1.RowHeaderBackground    = Brushes.White;
                c1FlexGrid1.TopLeftCellBackground  = Brushes.White;
                c1FlexGrid1.BorderBrush            = Brushes.WhiteSmoke;
                c1FlexGrid1.Background             = Brushes.White;
                c1FlexGrid1.RowBackground          = Brushes.White;
                c1FlexGrid1.BorderThickness        = new Thickness(0, 3, 0, 0);
                //find border of flexgrid and set it to APA style
                DependencyObject border = VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(c1FlexGrid1));
                (border as Border).BorderThickness = new Thickness(0, 1, 0, 1);
            }
            else
            {
                c1FlexGrid1.ColumnHeaderBackground = Brushes.LightBlue;
                c1FlexGrid1.RowHeaderBackground    = Brushes.LightBlue;
                c1FlexGrid1.TopLeftCellBackground  = Brushes.LightBlue;

                c1FlexGrid1.BorderThickness = new Thickness(1);
            }

            /////////////Col Headers//////////
            if (colheadermatrix != null)
            {
                for (int i = colheaders.Rows.Count; i < colheadermatrix.GetLength(0); i++)
                {
                    C1.WPF.FlexGrid.Row row = new C1.WPF.FlexGrid.Row();
                    colheaders.Rows.Add(row);
                    row.AllowMerging        = true;
                    row.HorizontalAlignment = HorizontalAlignment.Center;
                }
                for (int i = colheaders.Columns.Count; i < colheadermatrix.GetLength(1); i++) // creating col headers
                {
                    C1.WPF.FlexGrid.Column col = new C1.WPF.FlexGrid.Column();
                    colheaders.Columns.Add(col);
                    col.AllowMerging = true;

                    //for APA Style table
                    if (APA)
                    {
                    }
                }

                //fill col headers
                for (int i = 0; i < colheadermatrix.GetLength(0); i++)
                {
                    for (int j = 0; j < colheadermatrix.GetLength(1); j++)
                    {
                        if (colheadermatrix[i, j] != null && colheadermatrix[i, j].Trim().Equals(".-."))
                        {
                            colheaders[i, j] = "";//14Jul2014 filling empty header
                        }
                        else
                        {
                            colheaders[i, j] = colheadermatrix[i, j];
                        }
                    }
                }
            }
            /////////////Row Headers///////////
            if (rowheadermatrix != null)
            {
                for (int i = rowheaders.Columns.Count; i < rowheadermatrix.GetLength(1); i++)
                {
                    C1.WPF.FlexGrid.Column col = new C1.WPF.FlexGrid.Column();
                    col.AllowMerging      = true;
                    col.VerticalAlignment = VerticalAlignment.Top;
                    rowheaders.Columns.Add(col);
                }

                for (int i = rowheaders.Rows.Count; i < rowheadermatrix.GetLength(0); i++)
                {
                    C1.WPF.FlexGrid.Row row = new C1.WPF.FlexGrid.Row();
                    rowheaders.Rows.Add(row);
                    row.AllowMerging = true;

                    //for APA Style table
                    if (APA)
                    {
                    }
                }
            }
            //fill row headers
            if (IsEmptyOrNullArray(rowheadermatrix))//rowheader are empty or null
            {
                c1FlexGrid1.HeadersVisibility = HeadersVisibility.Column;
            }
            else
            {
                for (int i = 0; i < rowheadermatrix.GetLength(0); i++)
                {
                    for (int j = 0; j < rowheadermatrix.GetLength(1); j++)
                    {
                        if (rowheadermatrix[i, j] != null && rowheadermatrix[i, j].Trim().Equals(".-."))
                        {
                            rowheaders[i, j] = "";//14Jul2014 filling empty header
                        }
                        else
                        {
                            rowheaders[i, j] = rowheadermatrix[i, j];
                        }
                    }
                }
            }
            //Filling Data
            if (datamatrix != null)
            {
                bool isemptyrow;
                for (int rw = 0; rw < datamatrix.GetLength(0); rw++)
                {
                    isemptyrow = true;//assuming row is empty
                    for (int c = 0; c < datamatrix.GetLength(1); c++)
                    {
                        if (datamatrix[rw, c].Trim().Length > 0)
                        {
                            if (c1FlexGrid1.Columns.Count > c && c1FlexGrid1.Rows.Count > rw)
                            {
                                c1FlexGrid1[rw, c] = datamatrix[rw, c];
                            }
                            isemptyrow = false;// if it has atleast one column filled then row is not empty
                        }
                    }
                    //// hide or remove empty row////
                    if (isemptyrow)
                    {
                        c1FlexGrid1.Rows[rw].Visible = false;
                    }
                }
            }
            #endregion
        }
Example #20
0
 public AlbumCell(Row row)
     : base(row)
 {
 }
        private void FillColHeaders(string[] colHeaders, AUGrid c1fgrid)
        {
            bool iscolheaderchecked = true;// rowheaderscheck.IsChecked == true ? true : false;
            //creating row headers
            string[,] colheadersdata = new string[1, colHeaders.Length];
            ////creating data
            for (int r = 0; r < colheadersdata.GetLength(0); r++)
            {
                for (int c = 0; c < colheadersdata.GetLength(1); c++)
                {
                    colheadersdata[r, c] = colHeaders[c];
                }
            }

            //create & fill row headers
            bool fillcolheaders = iscolheaderchecked;
            if (fillcolheaders)
            {
                var FGcolheaders = c1fgrid.ColumnHeaders; 
                FGcolheaders.Rows[0].AllowMerging = true;
                FGcolheaders.Rows[0].HorizontalAlignment = HorizontalAlignment.Center;

                for (int i = FGcolheaders.Columns.Count; i < colheadersdata.GetLength(1); i++)
                {
                    C1.WPF.FlexGrid.Column col = new C1.WPF.FlexGrid.Column();
                    col.AllowMerging = true;
                    col.VerticalAlignment = VerticalAlignment.Top;
                    FGcolheaders.Columns.Add(col);
                }

                for (int i = FGcolheaders.Rows.Count; i < colheadersdata.GetLength(0); i++)
                {
                    C1.WPF.FlexGrid.Row row = new C1.WPF.FlexGrid.Row();
                    FGcolheaders.Rows.Add(row);
                    row.AllowMerging = true;
                }

                //fill row headers
                for (int i = 0; i < colheadersdata.GetLength(0); i++)
                    for (int j = 0; j < colheadersdata.GetLength(1); j++)
                    {
                        if (colheadersdata[i, j] != null && colheadersdata[i, j].Trim().Equals(".-."))
                            FGcolheaders[i, j] = "";//14Jul2014 filling empty header
                        else
                            FGcolheaders[i, j] = colheadersdata[i, j];
                    }
            }
        }
Example #22
0
        public MainWindow()
        {
            InitializeComponent();

            // create grid
            _flex = new C1FlexGrid();
            _flex.RowBackground = new SolidColorBrush(Colors.White);
            _flex.AlternatingRowBackground = _flex.RowBackground;
            _flex.GridLinesVisibility = C1.WPF.FlexGrid.GridLinesVisibility.All;
            LayoutRoot.Children.Add(_flex);

            // add extra column header row
            _flex.ColumnHeaders.Rows.Add(new Row());

            // set up merging
            _flex.AllowMerging = AllowMerging.ColumnHeaders;
            _flex.ColumnHeaders.Rows[0].AllowMerging = true;

            // add columns
            AddColumn("TRANSDUCERS", "No", typeof(int), 30, HorizontalAlignment.Center);
            AddColumn("TRANSDUCERS", "Use", typeof(string), 60, HorizontalAlignment.Right);
            AddColumn("TRANSDUCERS", "Name", typeof(string), 80, HorizontalAlignment.Left);
            AddColumn("TRANSDUCERS", "Parameter", typeof(string), 80, HorizontalAlignment.Left);
            AddColumn("TRANSDUCERS", "Fullscale", typeof(int), 60, HorizontalAlignment.Center);
            AddColumn("TRANSDUCERS", "Units", typeof(string), 40, HorizontalAlignment.Center);
            AddColumn("TRANSDUCERS", "Test Type", typeof(TestType), 140, HorizontalAlignment.Center);
            AddColumn("Input", "Enable", typeof(bool), 60, HorizontalAlignment.Center);
            AddColumn("Input", "Fault", typeof(FaultType), 40, HorizontalAlignment.Center);
            AddColumn("Sense", "Enable", typeof(bool), 60, HorizontalAlignment.Center);
            AddColumn("Sense", "Fault", typeof(FaultType), 40, HorizontalAlignment.Center);
            AddColumn("Excitation", "Enable", typeof(bool), 60, HorizontalAlignment.Center);
            AddColumn("Excitation", "Fault", typeof(FaultType), 40, HorizontalAlignment.Center);

            // use combo to edit 'Use' column
            var options = "FB,CT,JK,CB,TZ,LZ".Split(',');
            _flex.Columns["TRANSDUCERS.Use"].ValueConverter = new ColumnValueConverter(options, true);

            // add some data
            for (int i = 0; i < 10; i++)
            {
                var row = new Row();
                _flex.Rows.Add(row);
                row["TRANSDUCERS.No"] = i;
                row["TRANSDUCERS.Use"] = "FB";
                row["TRANSDUCERS.Name"] = "Hello";
                row["TRANSDUCERS.Parameter"] = "Disp - FB";
                row["TRANSDUCERS.Fullscale"] = 100;
                row["TRANSDUCERS.Units"] = "mm";
                row["Input.Enable"] = true;
                row["Input.Fault"] = FaultType.None;
                row["Sense.Enable"] = true;
                row["Sense.Fault"] = FaultType.None;
                row["Excitation.Enable"] = true;
                row["Excitation.Fault"] = FaultType.None;
            }

            // apply custom cell factory
            var cf = new MyCellFactory();
            _flex.CellFactory = cf;
            cf.CellValueChanged += cf_CellValueChanged;
        }
Example #23
0
 public ArtistCell(Row row)
     : base(row)
 {
 }
Example #24
0
        public ImageCell(Row row)
        {
            if (_imgSrc == null)
            {
                _imgSrc = GetImageSource(GetImageResourceName());
            }

            Orientation = Orientation.Horizontal;

            var img = new Image();
            img.Source = _imgSrc;
            img.Width = 25;
            img.Height = 15;
            img.VerticalAlignment = VerticalAlignment.Center;
            img.Stretch = Stretch.None;
            Children.Add(img);

            var tb = new TextBlock();
            tb.VerticalAlignment = VerticalAlignment.Center;
            Children.Add(tb);
            BindCell(row.DataItem);
        }