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);
                }
            }
        }
 private static void ApplyAttributes(Column c, string attName)
 {
     PropertyInfo propertyInfo = c.PropertyInfo;
     if (propertyInfo != null)
     {
         object[] customAttributes = propertyInfo.GetCustomAttributes(true);
         for (int i = 0; i < customAttributes.Length; i++)
         {
             object att = customAttributes[i];
             if (attName == att.GetType().Name)
             {
                 switch (attName)
                 {
                     case "DisplayAttribute":
                         ApplyDisplayAttribute(att, c);
                         break;
                     case "DisplayFormatAttribute":
                         ApplyDisplayFormatAttribute(att, c);
                         break;
                     case "EditableAttribute":
                         ApplyEditableAttribute(att, c);
                         break;
                 }
             }
         }
     }
 }
        public MainWindow()
        {
            InitializeComponent();

            // populate grid
            var c = new Column();
            c.Header = c.ColumnName = "Row#";
            c.IsReadOnly = true;
            _flex.Columns.Add(c);

            c = new Column();
            c.Header = c.ColumnName = "Cell Type";
            c.IsReadOnly = true;
            _flex.Columns.Add(c);

            c = new Column();
            c.Header = c.ColumnName = "Data";
            c.Width = new GridLength(250, GridUnitType.Pixel);
            _flex.Columns.Add(c);

            for (int i = 0; i < 50; i++)
            {
                AddRow(typeof(TextBox));
                AddRow(typeof(CheckBox));
                AddRow(typeof(ComboBox));
                AddRow(typeof(Slider));
                AddRow(typeof(C1ColorPicker));
            }

            // initialize custom cell factory
            _flex.Rows.MinSize = 35;
            _flex.CellFactory = new UnboundCellFactory(_flex);
            _ccf.Click += _ccf_Checked;
        }
 // ** object model
 public string GetFilterArgument(Column col)
 {
     string text;
     return _filterArgs.TryGetValue(col, out text)
         ? text
         : string.Empty;
 }
 private static void ApplyDisplayAttribute(object att, Column c)
 {
     if (c.AutoGenerated)
     {
         object value = GetValue(att, "AutoGenerateField");
         if (value is bool && !(bool) value)
         {
             c.Grid.Columns.Remove(c);
             return;
         }
     }
     string name = GetValue(att, "ShortName") as string;
     if (string.IsNullOrEmpty(name))
     {
         name = GetValue(att, "Name") as string;
     }
     if (!string.IsNullOrEmpty(name))
     {
         c.Header = name;
     }
     object order = GetValue(att, "Order");
     if (order is int)
     {
         ColumnCollection columns = c.Grid.Columns;
         if (c.Index != (int) order)
         {
             columns.Remove(c);
             int num = Math.Max(0, Math.Min(columns.Count, (int) order));
             columns.Insert(num, c);
         }
     }
 }
 internal ColumnFilter(C1FlexGridFilter owner, Column column)
 {
     Owner = owner;
     Column = column;
     DataType = column.DataType;
     ConditionFilter = new ConditionFilter(DataType);
     ValueFilter = new ValueFilter(DataType);
     FilterType = FilterType.Automatic;
 }
        void AddColumn(string name, Type type, string fmt)
        {
            var c = new C1.WPF.FlexGrid.Column();

            c.ColumnName = name;
            c.DataType   = type;
            c.Format     = fmt;
            _flexUnbound.Columns.Add(c);
        }
Exemple #8
0
 /// <summary>
 /// Gets the style applied to a cell in this row.
 /// </summary>
 public CellStyle GetCellStyle(Column col)
 {
     CellStyle s = null;
     if (_cellStyles != null)
     {
         _cellStyles.TryGetValue(col,out s);
     }
     return s;
 }
Exemple #9
0
 /// <summary>
 /// Gets the data in a cell as it should be shown in the editor
 /// (full formulas, raw values).
 /// </summary>
 /// <param name="col">Column that defines the cell to retrieve.</param>
 /// <returns></returns>
 public string GetDataEditor(Column col)
 {
     var text = GetFormula(col);
     if (text == null)
     {
         var val = GetDataRaw(col);
         text = val != null ? val.ToString() : string.Empty;
     }
     return text;
 }
Exemple #10
0
        // ** object model

        /// <summary>
        /// Applies a style to a cell in this row.
        /// </summary>
        public void SetCellStyle(Column col, CellStyle style)
        {
            if (!object.ReferenceEquals(style, GetCellStyle(col)))
            {
                if (_cellStyles == null)
                {
                    _cellStyles = new Dictionary<Column, CellStyle>();
                }
               _cellStyles[col] = style;
                if (Grid != null)
                {
                    Grid.Invalidate(new CellRange(this.Index, col.Index));
                }
            }
        }
        public void SetFilterArgument(Column col, string arg)
        {
            if (arg != GetFilterArgument(col))
            {
                // save argument
                _filterArgs[col] = arg;

                // save regex pattern to support wildcards
                arg = arg != null ? arg.Replace("%", ".*") : arg;
                _rxPattern[col] = string.Format("^{0}$", arg);

                // apply the filter
                ApplyFilter();
            }
        }
 public static void ApplyAttributes(C1FlexGrid flex)
 {
     var columnArray = new Column[flex.Columns.Count];
     flex.Columns.CopyTo(columnArray, 0);
     for (int i = 0; i < columnArray.Length; i++)
     {
         Column column = columnArray[i];
         ApplyAttributes(column, "DisplayAttribute");
         ApplyAttributes(column, "DisplayFormatAttribute");
         ApplyAttributes(column, "EditableAttribute");
     }
     for (int i = 0; i < columnArray.Length; i++)
     {
         Column column = columnArray[i];
         ApplyAttributes(column, "DisplayAttribute");
     }
 }
Exemple #13
0
        // ** object model
        /// <summary>
        /// Overridden to apply formatting when getting data.
        /// </summary>
        public override string GetDataFormatted(Column col)
        {
            // get data as usual
            dynamic data = GetDataRaw(col);

            // apply format
            dynamic ifmt = data as IFormattable;
            if (ifmt != null)
            {
                // get cell format
                dynamic s = GetCellStyle(col) as ExcelCellStyle;
                dynamic fmt = s != null && (!string.IsNullOrEmpty(s.Format)) ? s.Format : DEFAULT_FORMAT;
                data = ifmt.ToString(fmt, CultureInfo.CurrentUICulture);
            }

            // done
            return data != null ? data.ToString() : string.Empty;
        }
        public FilterEditor(GridFilterRow row, Column col)
        {
            InitializeComponent();

            // store grid parameters
            _grid = row.Grid;
            _row = row;
            _col = col;

            // initialize editor content from values stored in the row
            // (the editor is transient and can't be used for storage)
            var filterArgument = _row.GetFilterArgument(_col);

            if (_col.DataType == typeof(bool))
            {
                // show checkbox for Boolean values
                _cbValue.Visibility = System.Windows.Visibility.Visible;
                _tbValue.Visibility = System.Windows.Visibility.Hidden;

                // initialize editors
                bool cb;
                _cbValue.IsChecked = bool.TryParse(filterArgument, out cb) ? (bool?)cb : null;
                _tbValue.Text = null;
            }
            else
            {
                // show TextBox for non-Boolean values
                _cbValue.Visibility = System.Windows.Visibility.Hidden;
                _tbValue.Visibility = System.Windows.Visibility.Visible;

                // initialize editors
                _tbValue.Text = _row.GetFilterArgument(_col);
                _cbValue.IsChecked = null;
            }

            // show filter image if the filter is active
            UpdateFilterImage();
        }
Exemple #15
0
 /// <summary>
 ///     Gets or sets the value of a specific cell.
 /// </summary>
 /// <param name="row">Index of the row that contains the cell.</param>
 /// <param name="col">
 ///     <see cref="T:C1.WPF.FlexGrid.Column" /> that contains the cell.
 /// </param>
 /// <returns>The value of the cell.</returns>
 public object this[int row, Column col]
 {
     get { return Rows[row][col]; }
     set
     {
         Rows[row][col] = value;
         if (CellType != CellType.Cell)
         {
             Invalidate(new CellRange(row, col.Index));
         }
     }
 }
Exemple #16
0
 private static void BindAutoColumn(Column c, Type type)
 {
     Column column = c;
     string typeName = type != null ? type.Name : null;
     column.Header = typeName;
     Binding binding = new Binding();
     c.Binding = binding;
     binding.NotifyOnValidationError = true;
     binding.ValidatesOnExceptions = true;
     binding.Converter = new ValueTypeConverter();
     InitializeAutoColumn(c, type);
 }
Exemple #17
0
        /// <summary>
        /// Loads the content of an XLSheet into a C1FlexGrid.
        /// </summary>
        public static void Load(XLSheet sheet, C1FlexGrid flex)
        {
            // clear style cache if this is a new book
            if (sheet.Book != _lastBook)
            {
                _cellStyles.Clear();
                _excelStyles.Clear();
                _lastBook = sheet.Book;
            }

            // set default parameters
            flex.FontFamily = new FontFamily(sheet.Book.DefaultFont.FontName);
            flex.FontSize = PointsToPixels(sheet.Book.DefaultFont.FontSize);
            flex.Rows.DefaultSize = TwipsToPixels(sheet.DefaultRowHeight);
            flex.Columns.DefaultSize = TwipsToPixels(sheet.DefaultColumnWidth);
            flex.IsReadOnly = sheet.Locked;
            flex.GridLinesVisibility = sheet.ShowGridLines
                ? GridLinesVisibility.All
                : GridLinesVisibility.None;
            //flex.GridLinesBrush = sheet.GridColor;
            flex.HeadersVisibility = sheet.ShowHeaders
                ? HeadersVisibility.All
                : HeadersVisibility.None;
            flex.GroupRowPosition = sheet.OutlinesBelow
                ? GroupRowPosition.BelowData
                : GroupRowPosition.AboveData;

            // add columns
            flex.Columns.Clear();
            foreach (XLColumn c in sheet.Columns)
            {
                // create column, give it a unique name so undo/ColumnLayout work
                var col = new Column();
                col.ColumnName = col.GetHashCode().ToString("x0");

                // set size and visibility
                if (c.Width > -1)
                {
                    col.Width = new GridLength(TwipsToPixels(c.Width));
                }
                col.Visible = c.Visible;

                // set style
                if (c.Style != null)
                {
                    col.CellStyle = GetCellStyle(c.Style);
                }

                // and add to the grid
                flex.Columns.Add(col);
            }

            // add rows
            flex.Rows.Clear();
            foreach (XLRow r in sheet.Rows)
            {
                var row = new ExcelRow();
                if (r.Height > -1)
                {
                    row.Height = TwipsToPixels(r.Height);
                }
                if (r.Style != null)
                {
                    row.CellStyle = GetCellStyle(r.Style);
                }
                row.Level = r.OutlineLevel;
                row.Visible = r.Visible;
                flex.Rows.Add(row);
            }

            // add cells
            for (int r = 0; r < flex.Rows.Count; r++)
            {
                for (int c = 0; c < flex.Columns.Count; c++)
                {
                    var cell = sheet[r, c];
                    if (cell != null)
                    {
                        if (!string.IsNullOrEmpty(cell.Formula))
                        {
                            // save formula
                            var formula = cell.Formula.Trim();
                            if (!formula.StartsWith("="))
                            {
                                formula = string.Format("={0}", formula);
                            }
                            flex[r, c] = formula;
                        }
                        else if (cell.Value != null)
                        {
                            // save value
                            flex[r, c] = cell.Value;
                        }
                        if (cell.Style != null)
                        {
                            // save style
                            var row = flex.Rows[r] as ExcelRow;
                            var col = flex.Columns[c];
                            row.SetCellStyle(col, GetCellStyle(cell.Style));
                        }
                    }
                }
            }

            // at least 20 columns, 50 rows
            while (flex.Columns.Count < 20)
            {
                flex.Columns.Add(new Column());
            }
            while (flex.Rows.Count < 50)
            {
                flex.Rows.Add(new ExcelRow());
            }

            // load merged cells
            var xmm = flex.MergeManager as ExcelMergeManager;
            if (xmm == null)
            {
                xmm = new ExcelMergeManager();
            }
            xmm.GetMergedRanges(sheet);

            // freeze rows/columns
            flex.Rows.Frozen = sheet.Rows.Frozen;
            flex.Columns.Frozen = sheet.Columns.Frozen;

            // update selection
            if (sheet.SelectedCells != null && sheet.SelectedCells.Count > 0)
            {
                // review: using the last one seems to work, but why?
                var sel = sheet.SelectedCells[sheet.SelectedCells.Count - 1];
                flex.Select(sel.RowFrom, sel.ColumnFrom, sel.RowTo, sel.ColumnTo, false);
            }
            else
            {
                flex.Select(0, 0);
            }
        }
 internal void StartDraggingColumn(Column col)
 {
     C1FlexGrid flexGrid = FlexGrid;
     if (flexGrid != null && FinishEditing())
     {
         _dragSource = col;
         FrameworkElement cellElement = flexGrid.ColumnHeaders.GetCellElement(new CellRange(0, col.Index));
         _ddm.DoDragDrop(cellElement, DragMarkerColor);
     }
 }
        private static void BindingColumnsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            try
            {
                var bindingColumns = e.NewValue as ObservableCollection<ColumnConfig>;
                if(bindingColumns != null)
                {
                    var c1FlexGrid = d as C1FlexGrid;
                    if(c1FlexGrid != null)
                    {
                        //List<string> list = new List<string>
                        //{
                        //    "Viewership",
                        //    "Sentiment",
                        //    "AssociationAvg",
                        //    "PreAwareness",
                        //    "PostAwarenessAvg"
                        //};

                        C1FlexGridFilter filter = new C1FlexGridFilter();

                        c1FlexGrid.Columns.Clear();
                        foreach(var bindingColumn in bindingColumns)
                        {
                            var column = new Column
                            {
                                Header = bindingColumn.HeaderName,
                                Binding = new Binding(bindingColumn.ColumnName),
                                Width = new GridLength(bindingColumn.Width),
                                Format = bindingColumn.FormatString,
                                ToolTip = bindingColumn.HeaderDescription,
                                HorizontalAlignment = HorizontalAlignment.Left,
                                HeaderBackground =
                                    new SolidColorBrush(ColorConverter.ConvertFromString(bindingColumn.HeaderColorString) is Color ? (Color)ColorConverter.ConvertFromString(bindingColumn.HeaderColorString) : Colors.White)
                            };
                            c1FlexGrid.Columns.Add(column);
                            //if(list.Contains(bindingColumn.ColumnName))
                            //{
                            //    filter.GetColumnFilter(column);
                            //    var cf13 = filter.GetColumnFilter(column);
                            //    cf13.FilterType = FilterType.Value;

                            //    filter.Apply();
                            //}
                        }

                        #region 设置双列头

                        //var ch = c1FlexGrid.ColumnHeaders;
                        //ch.Rows.Add(new Row());

                        //ch[0, 0] = "省份城市";
                        //ch[1, 0] = "省名";

                        //ch[0, 1] = "省份城市";
                        //ch[1, 1] = "城市";

                        //// allow merging the first fixed row
                        //ch.Rows[0].AllowMerging = true;

                        #endregion

                        //c1FlexGrid.AutoSizeColumns(0, c1FlexGrid.Columns.Count - 1, 0);

                        c1FlexGrid.CellFactory = new FlexGridCellFactory();

                        filter.Owner = c1FlexGrid;
                    }
                }
            }
            catch(Exception ex)
            {
                ShowMessage.Show("列绑定出错");
                LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "Failed to BindingColumnsChanged", ex);
            }
            finally
            {
                if(LogHelper.LogLevel == LogLevelEnum.Debug || LogHelper.LogLevel == LogLevelEnum.Info)
                {
                    LogHelper.LogMessage(MethodBase.GetCurrentMethod().DeclaringType, LogHelper.LogLevel, "BindingColumnsChanged", null);
                }
            }
        }
Exemple #20
0
 private void GenerateColumns(Dictionary<string, CustomPropertyInfo> props)
 {
     if (props.Count != 0 || CollectionView == null)
     {
         foreach (CustomPropertyInfo value in props.Values)
         {
             Column column = new Column();
             BindAutoColumn(column, value);
             column.AutoGenerated = true;
             Columns.Add(column);
         }
         DataAnnotations.ApplyAttributes(this);
     }
     else
     {
         Type itemType = GetItemType(CollectionView);
         if (Util.Util.IsPrimitive(itemType))
         {
             Column column = new Column();
             BindAutoColumn(column, itemType);
             column.AutoGenerated = true;
             Columns.Add(column);
         }
     }
 }
Exemple #21
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
        }
 internal void SetFilter(Column column, ColumnFilter filter)
 {
     _filters[column] = filter;
     Apply();
 }
 public void ShowFilterEditor(Column col)
 {
     _filterFactory.ShowFilterEditor(col);
 }
        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];
                    }
            }
        }
Exemple #25
0
 private static void InitializeAutoColumn(Column c, Type type)
 {
     c.DataType = type;
     type = type.GetNonNullableType();
     if (type == typeof (string))
     {
         c.Width = new GridLength(180);
         return;
     }
     if (type.IsNumericIntegral())
     {
         c.Width = new GridLength(80);
         c.Format = "n0";
         return;
     }
     if (type.IsNumericNonIntegral())
     {
         c.Width = new GridLength(80);
         c.Format = "n2";
         return;
     }
     if (type == typeof (bool))
     {
         c.Width = new GridLength(60);
         return;
     }
     if (type == typeof (DateTime))
     {
         c.Format = "d";
     }
 }
Exemple #26
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;
                }
            }
        }
Exemple #27
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;
 }
 // get a column name suitable for showing in the drop-down
 string GetColumnName(Column c)
 {
     var colName = C1FlexGridBook.GetAlphaColumnHeader(c.Index);
     return string.Format("Column {0}", colName);
 }
Exemple #29
0
 private static string GetColumnStyle(Column c)
 {
     StringBuilder sb = new StringBuilder();
     sb.AppendFormat("width:{0}px; ", (int) c.ActualWidth);
     if (c.HorizontalAlignment.HasValue)
     {
         if (c.HorizontalAlignment.Value == HorizontalAlignment.Center)
         {
             sb.Append("text-align:center; ");
         }
         else if (c.HorizontalAlignment.Value == HorizontalAlignment.Right)
         {
             sb.Append("text-align:right; ");
         }
     }
     return sb.ToString();
 }
        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];
                    }
            }
        }
Exemple #31
0
 private void BindAutoColumn(Column c, CustomPropertyInfo cpi)
 {
     Binding binding = new Binding();
     binding.Path = new PropertyPath(cpi.Name);
     binding.Mode = (cpi.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay);
     binding.Converter = _defaultColumnValueConverter;
     binding.ConverterParameter = c;
     Util.Util.SetBindingValidation(binding, ShowErrors);
     c.ColumnName = cpi.DisplayName;
     c.Binding = binding;
     c.PropertyInfo = cpi.PropertyInfo;
     c.IsReadOnly = cpi.IsReadOnly;
     InitializeAutoColumn(c, cpi.PropertyType);
 }
        // populate unbound FlexGrid
        void ShowPersonOnGrid(Person p, C1FlexGrid flex)
        {
            // initialize grid
            flex.Rows.Clear();
            flex.Columns.Clear();

            // add columns we want to show
            var c = new Column();
            c.Header = "Name";
            c.Binding = new System.Windows.Data.Binding("Name");
            c.Width = new GridLength(1, GridUnitType.Star);
            flex.Columns.Add(c);

            c = new Column();
            c.Header = "Children";
            c.Binding = new System.Windows.Data.Binding("Children.Count");
            c.HorizontalAlignment = HorizontalAlignment.Right;
            flex.Columns.Add(c);

            using (flex.Rows.DeferNotifications())
            {
                AddPersonToGrid(p, flex, 0);
            }
        }
 public ColumnFilter GetColumnFilter(Column column)
 {
     if (!_filters.ContainsKey(column))
     {
         _filters[column] = new ColumnFilter(this, column);
     }
     return _filters[column];
 }