/// <summary> /// Initialise default values /// </summary> private void Init() { this.key = ""; this.dataMember = ""; this.dictionary = null; this.caption = ""; this.width = I3Column.DefaultWidth_Const; this.columnState = I3ColumnState.Normal; this.headerAlignment = I3ColumnAlignment.Center; this.cellAlignment = I3ColumnAlignment.Left; this.image = null; this.imageOnRight = false; this.columnModel = null; this.x = 0; this.tooltipText = null; this.format = ""; this.sortOrder = SortOrder.None; this.renderer = null; this.editor = null; this.comparer = null; this.isSelected = false; this.cellTextAutoWarp = false; this.state = (byte)(STATE_ENABLED_Const | STATE_EDITABLE_Const | STATE_VISIBLE_Const | STATE_SELECTABLE_Const | STATE_SORTABLE_Const); }
/// <summary> /// 根据列设置数据设置I3ColumnModel的列属性 /// 注意:在没有行数据时才能执行此功能 如果有排序,在数据加载后,应该重新调用ColumnDisplayHelper.ReSort(I3ColumnModel)方法 /// </summary> /// <param name="model"></param> /// <param name="displayData"></param> public static void SetDisplayData(I3ColumnModel model, List <ColumnDisplayItem> displayData) { if (model == null) { return; } if (model.Table != null && model.Table.TableModel != null && model.Table.TableModel.Rows.Count > 0) { throw new Exception("can not set displayData when the tableModel has data."); } if (model.Table != null) { model.Table.BeginUpdate(); } try { //记录所有列 List <I3Column> tmpList = new List <I3Column>(); foreach (I3Column column in model.Columns) { tmpList.Add(column); } List <I3Column> list = new List <I3Column>(); //按displayData中的顺序添加列 foreach (ColumnDisplayItem item in displayData) { foreach (I3Column column in model.Columns) { if (string.Equals(column.Key, item.Key)) { column.Visible = item.Visible; column.Width = item.Width; column.InternalSortOrder = item.SortOrder; tmpList.Remove(column); list.Add(column); break; } } } //添加所有还没有处理的列 list.AddRange(tmpList); //添加到columnModel model.Columns.Clear(); model.Columns.AddRange(list.ToArray()); model.Columns.RecalcWidthCache(); } finally { if (model.Table != null) { model.Table.EndUpdate(); } } }
/// <summary> /// 获取I3ColumnModel的列设置数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public static List <ColumnDisplayItem> GetDisplayData(I3ColumnModel model) { List <ColumnDisplayItem> result = new List <ColumnDisplayItem>(); foreach (I3Column column in model.Columns) { ColumnDisplayItem item = new ColumnDisplayItem(column.Key, column.Visible, column.Width, column.SortOrder); result.Add(item); } return(result); }
/// <summary> /// A local cache of the last visible column in the collection /// </summary> //private int lastVisibleColumn; #endregion #region Constructor /// <summary> /// Initializes a new instance of the ColumnModel.ColumnCollection class /// that belongs to the specified ColumnModel /// </summary> /// <param name="owner">A ColumnModel representing the columnModel that owns /// the Column collection</param> public I3ColumnCollection(I3ColumnModel owner) : base() { if (owner == null) { throw new ArgumentNullException("owner"); } this.owner = owner; this.totalColumnWidth = 0; this.visibleColumnsWidth = 0; this.visibleColumnCount = 0; //this.lastVisibleColumn = -1; }
/// <summary> /// 在加载数据后,重新应用排序选项 /// </summary> /// <param name="model"></param> public static void ReSort(I3ColumnModel model) { if (model == null || model.Table == null || model.Table.TableModel == null || model.Table.TableModel.Rows.Count == 0) { return; } foreach (I3Column column in model.Columns) { if (column.Sortable && column.Visible && column.SortOrder != SortOrder.None) { model.Table.Sort(model.Columns.IndexOf(column), column.SortOrder); break; } } }
/// <summary> /// /// </summary> /// <param name="model"></param> /// <returns></returns> public void AddColumns(I3ColumnModel model) { this.model = model; //this.columnTable.HeaderRenderer = model.Table.HeaderRenderer; I3CellStyle cellStyle = new I3CellStyle(); cellStyle.Padding = new I3CellPadding(0, 0, 0, 0); this.columnTable.BeginUpdate(); for (int i = 0; i < model.Columns.Count; i++) { I3Row row = new I3Row(); I3Cell cell = new I3Cell("", model.Columns[i].Visible); cell.Tag = model.Columns[i].Width; cell.CellStyle = cellStyle; row.Cells.Add(cell); cell = new I3Cell(model.Columns[i].Caption); cell.Tag = model.Columns[i].Width; cell.CellStyle = cellStyle; row.Cells.Add(cell); this.columnTable.TableModel.Rows.Add(row); } this.columnTable.SelectionChanged += new IE310.Table.Events.I3SelectionEventHandler(columnTable_SelectionChanged); this.columnTable.CellCheckChanged += new IE310.Table.Events.I3CellCheckBoxEventHandler(columnTable_CellCheckChanged); if (this.columnTable.VScroll) { this.columnTable.ColumnModel.Columns[0].Width -= SystemInformation.VerticalScrollBarWidth; } if (this.columnTable.TableModel.Rows.Count > 0) { this.columnTable.TableModel.Selections.SelectCell(0, 0); } this.columnTable.EndUpdate(); }
private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); this.okButton = new System.Windows.Forms.Button(); this.cancelButton = new System.Windows.Forms.Button(); this.columnTable = new IE310.Table.Models.I3Table(); this.columnModel1 = new IE310.Table.Column.I3ColumnModel(); this.cbc = new IE310.Table.Column.I3CheckBoxColumn(); this.tc = new IE310.Table.Column.I3TextColumn(); this.tableModel1 = new IE310.Table.Row.I3TableModel(); this.button3 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.columnTable)).BeginInit(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.groupBox1.Location = new System.Drawing.Point(8, 375); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(322, 8); this.groupBox1.TabIndex = 9; this.groupBox1.TabStop = false; // // okButton // this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.okButton.FlatStyle = System.Windows.Forms.FlatStyle.System; this.okButton.Location = new System.Drawing.Point(168, 395); this.okButton.Name = "okButton"; this.okButton.Size = new System.Drawing.Size(75, 23); this.okButton.TabIndex = 10; this.okButton.Text = "确定"; this.okButton.Click += new System.EventHandler(this.okButton_Click); // // cancelButton // this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.cancelButton.FlatStyle = System.Windows.Forms.FlatStyle.System; this.cancelButton.Location = new System.Drawing.Point(253, 395); this.cancelButton.Name = "cancelButton"; this.cancelButton.Size = new System.Drawing.Size(75, 23); this.cancelButton.TabIndex = 11; this.cancelButton.Text = "取消"; // // columnTable // this.columnTable.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.columnTable.ColumnHeaderDisplayMode = IE310.Table.Header.I3ColumnHeaderDisplayMode.Text; this.columnTable.ColumnModel = this.columnModel1; this.columnTable.EnableToolTips = true; this.columnTable.ExtendLastCol = true; this.columnTable.GridColor = System.Drawing.SystemColors.ActiveCaption; this.columnTable.HeaderFont = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Bold); this.columnTable.Location = new System.Drawing.Point(12, 46); this.columnTable.Name = "columnTable"; this.columnTable.RowHeaderDisplayMode = IE310.Table.Header.I3RowHeaderDisplayMode.Num; this.columnTable.Size = new System.Drawing.Size(316, 323); this.columnTable.TabIndex = 1; this.columnTable.TableModel = this.tableModel1; this.columnTable.ToolTipAutomaticDelay = 1000; this.columnTable.ToolTipAutoPopDelay = 10000; this.columnTable.UnfocusedSelectionBackColor = System.Drawing.SystemColors.Highlight; this.columnTable.UnfocusedSelectionForeColor = System.Drawing.SystemColors.HighlightText; // // columnModel1 // this.columnModel1.ColumnHeaderHeight = 20; this.columnModel1.Columns.AddRange(new IE310.Table.Column.I3Column[] { this.cbc, this.tc }); // // cbc // this.cbc.Caption = "选择"; this.cbc.CellAlignment = IE310.Table.Column.I3ColumnAlignment.Center; this.cbc.CheckBoxColumnStyle = IE310.Table.Column.I3CheckBoxColumnStyle.Image; this.cbc.CustomCheckImage = null; this.cbc.CustomCheckImageFillClient = false; this.cbc.CustomCheckImageSize = new System.Drawing.Size(24, 18); this.cbc.DataMember = ""; this.cbc.Dictionary = null; this.cbc.DrawText = false; this.cbc.IsSelected = false; this.cbc.Key = ""; this.cbc.NeedWidth = 34.76953F; this.cbc.Sortable = false; this.cbc.Tag = null; this.cbc.ToolTipText = "点击左键全选\r\n点击右键反选"; this.cbc.Width = 49; // // tc // this.tc.Caption = "列名"; this.tc.CellAlignment = IE310.Table.Column.I3ColumnAlignment.Center; this.tc.DataMember = ""; this.tc.Dictionary = null; this.tc.Editable = false; this.tc.IsSelected = false; this.tc.Key = ""; this.tc.NeedWidth = 34.76953F; this.tc.Sortable = false; this.tc.Tag = null; this.tc.Width = 225; // // tableModel1 // this.tableModel1.DataSource = null; this.tableModel1.DefaultRowHeight = 20; // // button3 // this.button3.Image = global::IE310.Table.Properties.Resources.backselect32; this.button3.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; this.button3.Location = new System.Drawing.Point(150, 12); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(58, 23); this.button3.TabIndex = 14; this.button3.Text = "反选"; this.button3.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // button2 // this.button2.Image = global::IE310.Table.Properties.Resources.unselect32; this.button2.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; this.button2.Location = new System.Drawing.Point(76, 12); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(68, 23); this.button2.TabIndex = 13; this.button2.Text = "全不选"; this.button2.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // button1 // this.button1.Image = global::IE310.Table.Properties.Resources.allselect32; this.button1.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; this.button1.Location = new System.Drawing.Point(12, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(58, 23); this.button1.TabIndex = 12; this.button1.Text = "全选"; this.button1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // I3ShowColumnsDialog // this.AcceptButton = this.okButton; this.AutoScaleBaseSize = new System.Drawing.Size(5, 14); this.CancelButton = this.cancelButton; this.ClientSize = new System.Drawing.Size(339, 431); this.Controls.Add(this.button3); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Controls.Add(this.cancelButton); this.Controls.Add(this.okButton); this.Controls.Add(this.groupBox1); this.Controls.Add(this.columnTable); this.Font = new System.Drawing.Font("Tahoma", 8.25F); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "I3ShowColumnsDialog"; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "列设置"; ((System.ComponentModel.ISupportInitialize)(this.columnTable)).EndInit(); this.ResumeLayout(false); }