代码较多,只能贴出一部分,实际上就是设置Editor属性
- //---------------------------------------------------------------------------------
- // ** show built-in editors
- CellStyle cs = _flex.Styles.Add("Built-In Editors");
- cs.UserData =
- @"\b ** Built-In Editors\b0\par " +
- @"These cells use the C1FlexGrid built-in editors, controlled by " +
- @"the setting of the DataType, DataMap, ComboList, and EditMask properties.";
- // add boolean row (with checkbox)
- _flex.Rows.Count = 1;
- Row r = _flex.Rows.Add();
- r.Caption = "CheckBox";
- r.DataType = typeof(bool);
- r.Style.MergeWith(cs);
- // add boolean row (text mapped)
- r = _flex.Rows.Add();
- r.Caption = "ToggleText";
- r.DataType = typeof(bool);
- r.Format = "Yes;No";
- r.TextAlign= TextAlignEnum.CenterCenter;
- r.Style.MergeWith(cs);
- // add popup row
- r = _flex.Rows.Add();
- r.Caption = "Popup";
- r.ComboList= "...";
- r.Style.MergeWith(cs);
- // add editable popup row
- r = _flex.Rows.Add();
- r.Caption = "PopEdit";
- r.ComboList= "|...";
- r.Style.MergeWith(cs);
- var c= _flex.Cols[2];
-
- c.ComboList = "|...";
- c.Style.MergeWith(cs);
- // add row with masked textbox
- r = _flex.Rows.Add();
- r.Caption = "TextBox";
- r.EditMask = "(999) 999-9999";
- r.Style.MergeWith(cs);
- // add row with simple list
- r = _flex.Rows.Add();
- r.Caption = "List";
- r.ComboList= comboList;
- r.Style.WordWrap = true;
- r.Style.MergeWith(cs);
- // add row with combo list
- r = _flex.Rows.Add();
- r.Caption = "Combo";
- r.ComboList= "|" + comboList;
- r.TextAlign= TextAlignEnum.CenterCenter;
- r.Style.MergeWith(cs);
- // add row with date time picker
- r = _flex.Rows.Add();
- r.Caption = "DateTime";
- r.DataType = typeof(DateTime);
- r.Style.MergeWith(cs);
- // add row with time picker
- r = _flex.Rows.Add();
- r.Caption = "Time";
- r.DataType = typeof(DateTime);
- r.Format = "HH:mm";
- r.Style.MergeWith(cs);
- // add row with data/image maps
- r = _flex.Rows.Add();
- r.Caption = "Data/ImageMaps";
- r.DataType = typeof(int);
- r.ImageMap = imgMap;
- r.DataMap = dataMap;
- r.TextAlign= TextAlignEnum.LeftCenter;
- r.Style.MergeWith(cs);
- //---------------------------------------------------------------------------------
- // ** show regular controls used as editors
- cs = _flex.Styles.Add("Regular Controls");
- cs.BackColor = Color.Linen;
- cs.UserData =
- @"\b ** Regular Controls\b0\par " +
- @"These cells use regular .NET controls as grid editors. The controls were added " +
- @"to the form at design time and assigned to grid rows. Their functionality is somewhat " +
- @"limited because they don't implement the IC1EmbeddedEditor interface.";
- // add row with custom editor (TextBox)
- r = _flex.Rows.Add();
- r.Caption = "TextBox";
- r.Editor = textBox1;
- r.Style.MergeWith(cs);
- // add row with custom editor (Combo)
- r = _flex.Rows.Add();
- r.Caption = "ComboBox";
- r.DataType = typeof(string);
- r.Editor = comboBox1;
- r.Style.MergeWith(cs);
- // add row with custom editor (DomainUpDown)
- r = _flex.Rows.Add();
- r.Caption = "DomainUpDown";
- r.DataType = typeof(string);
- r.Editor = domainUpDown1;
- r.Style.MergeWith(cs);
- // add row with custom editor (NumericUpDown)
- r = _flex.Rows.Add();
- r.Caption = "NumericUpDown";
- r.DataType = typeof(double);
- r.Editor = numericUpDown1;
- r.Style.MergeWith(cs);
- //---------------------------------------------------------------------------------
- // ** show custom editors based on regular controls
- cs = _flex.Styles.Add("Custom Controls");
- cs.BackColor = Color.LightGoldenrodYellow;
- cs.UserData =
- @"\b ** Custom Controls\b0\par " +
- @"These cells use custom controls that inherit from the base .NET controls " +
- @"and implement methods in the IC1EmbeddedEditor interface. Because the grid " +
- @"binds using reflection, you don't have to implement the entire interface, only " +
- @"the methods that are relevant to your specific control.";
- // add row with custom editor (Numeric, integer, positive, no calculator)
- r = _flex.Rows.Add();
- r.Caption = "Positive Integer";
- r.DataType = typeof(int);
- r.Format = "#,###";
- r.Editor = new NumericTextBox(r.Format, false);
- ((NumericTextBox)r.Editor).Minimum = 0;
- r.Style.MergeWith(cs);
- // add row with custom editor (Numeric, three decimals, no calculator)
- r = _flex.Rows.Add();
- r.Caption = "Double";
- r.DataType = typeof(double);
- r.Format = "#,###.000";
- r.Editor = new NumericTextBox(r.Format, false);
- r.Style.MergeWith(cs);
- // add row with custom editor (Numeric, two decimals, calculator)
- r = _flex.Rows.Add();
- r.Caption = "Calculator";
- r.DataType = typeof(double);
- r.Format = "#,###.000";
- r.Editor = new NumericTextBox(r.Format, true);
- r.Style.MergeWith(cs);
复制代码 |