.Net强大的列表控件XPTable [转]
.Net强大的列表控件XPTable
http://blog.csdn.net/bodybo/article/details/7359531
XPTable的大名,想必C#开发的人都有所耳闻,使用下来确实强大,在表格中添加下拉列表、进度条、图标等非常容易,灵活方便。当添加大量数据时,和.Net自带的ListView对比过,速度快很多!

XPTable最重要的是开源,可根据自己的需要修改,有bug也可想办法解决。我就对其进行了若干处改进,解决了部分bug。源代码写的非常标准,架构设计也很值得借鉴,研读源代码本身就是个学习提高的过程。真心感谢将如此完美的代码公开分享的人,作为点滴回报,也将自己修改后的源码放出,供大家参考,和原作者的贡献比起来,我这点小小的修改就如沧海一粟,不足为道了。
我修改过的代码和解决的问题列示如下(下载我的源代码,在项目中搜索chenbo,就能看到修改注释):
1、...\Models\Table.cs Line 2118,2153
解决问题:在某些情况下(任意调整窗口大小,XPTable的Anchor设置为随窗口大小自适应调整)会抛System.ArgumentOutOfRangeException异常,vScrollBar.LargeChange不能小于0
2、...\Models\Table.cs Line 5598,5606
解决问题:在列头Resizing状态下双击鼠标,应根据该列数据中最长的一行调整当前列宽度,目前仅对TextColumn和NumberColumn有效
3、...\Models\Table.cs Line 6134
解决问题:在列头Resizing状态下单击鼠标,避免OnMouseUp激发列宽的调整。应该双击或者调整宽度后才能激发
4、...\Models\Table.cs Line 6373
解决问题:根据原代码,如果Table允许多选,选中多行后,点鼠标右键将自动选择鼠标所在行,修改后,多选的行依然选中
这个问题借鉴了“恶猫的尾巴”的代码:http://emao.me/tag/XpTable/,在此感谢!
5、...\Models\Table.cs Line 6627
解决问题:鼠标在列头为Resizing图标时,移动到数据区域不会自动变为默认图标
6、...\Models\Table.cs Line 7229
解决问题:解决列头的对齐方式始终是靠左的问题
7、...\Renderers\NumberCellRenderer.cs Line 661
解决问题:为了实现Table.cs的函数CalColumnWidth中实现对NumberColumn列格式化数据宽度的计算
8、... 刚下载源码后即发现的问题,好像是某个函数col参数有问题,具体不记得哪个文件哪行代码了
我修改后的源代码和Dll下载链接(VS2008 .NetFramework 2.0)
自己写了控制类(TableCtrl.cs)来操作XPTable,使用起来更方便
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using XPTable;
- using XPTable.Models;
- using XPTable.Editors;
- namespace ProgramModule
- {
- struct Key
- {
- public string name;
- public object value;
- };
- class TableKey
- {
- private List<Key> m_keys;
- public TableKey()
- {
- m_keys = new List<Key>();
- }
- public void AddKey(string name, object value)
- {
- Key key;
- key.name = name;
- key.value = value;
- m_keys.Add(key);
- }
- public int Count
- {
- get
- {
- return m_keys.Count;
- }
- }
- public string GetKeyName(int index)
- {
- if (index < 0 || index >= Count)
- {
- return "";
- }
- else
- {
- return m_keys[index].name;
- }
- }
- public object GetKeyValue(int index)
- {
- if (index < 0 || index >= Count)
- {
- return null;
- }
- else
- {
- return m_keys[index].value;
- }
- }
- };
- static class TableCtrl
- {
- const int COLOR_WINDOW = 5;
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
- private static extern int GetSysColor(int nIndex);
- public static Color GetSysWindowColor()
- {
- Color color;
- int iColor = GetSysColor(COLOR_WINDOW);
- color = Color.FromArgb(255, Color.FromArgb(iColor));
- return color;
- }
- public static void InitTable(ref Table table)
- {
- try
- {
- table.NoItemsText = "";
- table.GridLines = GridLines.Both;
- table.ColumnModel = new ColumnModel();
- table.TableModel = new TableModel();
- table.TableModel.RowHeight = 18;
- TextColumn textColKey = new TextColumn("key", 70);
- textColKey.Visible = false;
- table.ColumnModel.Columns.Add(textColKey);
- table.FullRowSelect = true;
- table.HideSelection = false;
- table.BackColor = GetSysWindowColor();
- table.SortedColumnBackColor = Color.FromArgb(100, Color.WhiteSmoke);
- }
- catch (System.Exception ex)
- {
- GlobalFunction.MsgBoxException(ex.Message, "InitTable");
- }
- }
- public static void AddColumn(ref Table table, Column column)
- {
- column.Editable = false;
- column.Sortable = true;
- table.ColumnModel.Columns.Add(column);
- }
- public static void AddColumn(ref Table table, Column column, bool editable, bool sortable)
- {
- column.Editable = editable;
- column.Sortable = sortable;
- table.ColumnModel.Columns.Add(column);
- }
- public static void AddColumn(ref Table table, Column column, bool editable, bool sortable, ColumnAlignment alignment)
- {
- column.Editable = editable;
- column.Sortable = sortable;
- column.Alignment = alignment;
- table.ColumnModel.Columns.Add(column);
- }
- public static void AddNumColumn(ref Table table, NumberColumn column, bool editable, bool sortable, bool showUpDownButton, double minValue, double MaxValue, string format, ColumnAlignment alignment)
- {
- column.Editable = editable;
- column.Sortable = sortable;
- column.ShowUpDownButtons = showUpDownButton;
- column.Minimum = Convert.ToDecimal(minValue);
- column.Maximum = Convert.ToDecimal(MaxValue);
- column.Format = format;
- column.Alignment = alignment;
- table.ColumnModel.Columns.Add(column);
- }
- //public static int AddNewRow(ref Table table)
- //{
- // Row row = new Row();
- // for (int i = 0; i < table.ColumnModel.Columns.Count; i++ )
- // {
- // row.Cells.Add(new Cell());
- // }
- // return table.TableModel.Rows.Add(row);
- //}
- public static Row AddNewRow(ref Table table)
- {
- try
- {
- Row row = new Row();
- for (int i = 0; i < table.ColumnModel.Columns.Count; i++)
- {
- row.Cells.Add(new Cell());
- }
- table.TableModel.Rows.Add(row);
- return row;
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "AddNewRow");
- return null;
- }
- }
- public static Row AddNewRow(ref Table table, string key)
- {
- try
- {
- foreach (Row row1 in table.TableModel.Rows)
- {
- if (row1.Cells[0].Text == key)
- {
- GlobalFunction.MsgBoxError("key is not unique");
- return null;
- }
- }
- Row row = new Row();
- for (int i = 0; i < table.ColumnModel.Columns.Count; i++)
- {
- row.Cells.Add(new Cell());
- }
- row.Cells[0].Text = key;
- table.TableModel.Rows.Add(row);
- return row;
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "AddNewRow");
- return null;
- }
- }
- public static void RemoveRow(ref Table table, int rowIndex)
- {
- try
- {
- table.TableModel.Rows.RemoveAt(rowIndex);
- }
- catch (System.Exception e)
- {
- MessageBox.Show("RemoveRow:" + e.Message);
- }
- }
- public static void RemoveRow(ref Table table, Row row)
- {
- try
- {
- table.TableModel.Rows.Remove(row);
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "RemoveRow");
- }
- }
- public static void RemoveRowAll(ref Table table)
- {
- try
- {
- table.TableModel.Rows.Clear();
- }
- catch (System.Exception e)
- {
- MessageBox.Show("RemoveRowAll:" + e.Message);
- }
- }
- public static void SetTableValue(ref Table table, int rowIndex, string colName, object value)
- {
- try
- {
- Column targetCol = null;
- int colIndex = -1;
- if (rowIndex < 0 || rowIndex >= table.TableModel.Rows.Count)
- {
- return;
- }
- for (int i = 0; i < table.ColumnModel.Columns.Count; i++)
- {
- if (table.ColumnModel.Columns[i].Text == colName)
- {
- targetCol = table.ColumnModel.Columns[i];
- colIndex = i;
- break;
- }
- }
- if (colIndex == -1)
- {
- return;
- }
- if (targetCol is TextColumn || targetCol is ComboBoxColumn || targetCol is ButtonColumn)
- {
- table.TableModel.Rows[rowIndex].Cells[colIndex].Text = value.ToString();
- }
- else if (targetCol is CheckBoxColumn)
- {
- table.TableModel.Rows[rowIndex].Cells[colIndex].Checked = (bool)value;
- }
- else if (targetCol is ImageColumn)
- {
- table.TableModel.Rows[rowIndex].Cells[colIndex].Image = (Image)value;
- }
- else if (targetCol is NumberColumn)
- {
- if (GlobalFunction.IsNumeric(value.ToString()))
- {
- table.TableModel.Rows[rowIndex].Cells[colIndex].Data = Convert.ToDouble(value);
- }
- }
- else
- {
- table.TableModel.Rows[rowIndex].Cells[colIndex].Data = value;
- }
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "SetTableValue");
- }
- }
- public static void SetTableValue(ref Table table, int rowIndex, int colIndex, object value)
- {
- try
- {
- if (colIndex <= 0)
- {
- return;
- }
- Column targetCol = table.ColumnModel.Columns[colIndex];
- if (targetCol is TextColumn || targetCol is ComboBoxColumn || targetCol is ButtonColumn)
- {
- table.TableModel.Rows[rowIndex].Cells[colIndex].Text = value.ToString();
- }
- else if (targetCol is CheckBoxColumn)
- {
- table.TableModel.Rows[rowIndex].Cells[colIndex].Checked = (bool)value;
- }
- else if (targetCol is ImageColumn)
- {
- table.TableModel.Rows[rowIndex].Cells[colIndex].Image = (Image)value;
- }
- else if (targetCol is NumberColumn)
- {
- if (GlobalFunction.IsNumeric(value.ToString()))
- {
- table.TableModel.Rows[rowIndex].Cells[colIndex].Data = Convert.ToDouble(value);
- }
- }
- else
- {
- table.TableModel.Rows[rowIndex].Cells[colIndex].Data = value;
- }
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "SetTableValue");
- }
- }
- public static void SetTableValue(ref Table table, Row row, string colName, object value)
- {
- try
- {
- Column targetCol = null;
- int colIndex = -1;
- if (row == null)
- {
- return;
- }
- for (int i = 0; i < table.ColumnModel.Columns.Count; i++)
- {
- if (table.ColumnModel.Columns[i].Text == colName)
- {
- targetCol = table.ColumnModel.Columns[i];
- colIndex = i;
- break;
- }
- }
- if (colIndex == -1)
- {
- return;
- }
- if (targetCol is TextColumn || targetCol is ComboBoxColumn || targetCol is ButtonColumn)
- {
- row.Cells[colIndex].Text = value.ToString();
- }
- else if (targetCol is CheckBoxColumn)
- {
- row.Cells[colIndex].Checked = (bool)value;
- }
- else if (targetCol is ImageColumn)
- {
- row.Cells[colIndex].Image = (Image)value;
- }
- else if (targetCol is NumberColumn)
- {
- string val = "";
- if (GlobalFunction.FormatNumber(value.ToString(), 8, ref val))
- {
- row.Cells[colIndex].Data = Convert.ToDouble(val);
- }
- //if (GlobalFunction.IsNumeric(value.ToString()))
- //{
- //}
- }
- else
- {
- row.Cells[colIndex].Data = value;
- }
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "SetTableValue");
- }
- }
- public static void SetTableValueCheckbox(ref Table table, int rowIndex, string colName, string text, bool check)
- {
- try
- {
- Column targetCol = null;
- int colIndex = -1;
- if (rowIndex < 0 || rowIndex >= table.TableModel.Rows.Count)
- {
- return;
- }
- for (int i = 0; i < table.ColumnModel.Columns.Count; i++)
- {
- if (table.ColumnModel.Columns[i].Text == colName)
- {
- targetCol = table.ColumnModel.Columns[i];
- colIndex = i;
- break;
- }
- }
- if (colIndex == -1)
- {
- return;
- }
- if (targetCol is CheckBoxColumn)
- {
- table.TableModel.Rows[rowIndex].Cells[colIndex].Text = text;
- table.TableModel.Rows[rowIndex].Cells[colIndex].Checked = check;
- }
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "SetTableValueCheckbox");
- }
- }
- public static void SetTableValueCheckbox(ref Table table, Row row, string colName, string text, bool check)
- {
- try
- {
- Column targetCol = null;
- int colIndex = -1;
- if (row == null)
- {
- return;
- }
- for (int i = 0; i < table.ColumnModel.Columns.Count; i++)
- {
- if (table.ColumnModel.Columns[i].Text == colName)
- {
- targetCol = table.ColumnModel.Columns[i];
- colIndex = i;
- break;
- }
- }
- if (colIndex == -1)
- {
- return;
- }
- if (targetCol is CheckBoxColumn)
- {
- row.Cells[colIndex].Text = text;
- row.Cells[colIndex].Checked = check;
- }
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "SetTableValueCheckbox");
- }
- }
- public static void SetTableValueImage(ref Table table, int rowIndex, string colName, string text, Image image)
- {
- try
- {
- Column targetCol = null;
- int colIndex = -1;
- if (rowIndex < 0 || rowIndex >= table.TableModel.Rows.Count)
- {
- return;
- }
- for (int i = 0; i < table.ColumnModel.Columns.Count; i++)
- {
- if (table.ColumnModel.Columns[i].Text == colName)
- {
- targetCol = table.ColumnModel.Columns[i];
- colIndex = i;
- break;
- }
- }
- if (colIndex == -1)
- {
- return;
- }
- if (targetCol is ImageColumn)
- {
- table.TableModel.Rows[rowIndex].Cells[colIndex].Text = text;
- table.TableModel.Rows[rowIndex].Cells[colIndex].Image = image;
- }
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "SetTableValueImage");
- }
- }
- public static void SetTableValueImage(ref Table table, Row row, string colName, string text, Image image)
- {
- try
- {
- Column targetCol = null;
- int colIndex = -1;
- if (row == null)
- {
- return;
- }
- for (int i = 0; i < table.ColumnModel.Columns.Count; i++)
- {
- if (table.ColumnModel.Columns[i].Text == colName)
- {
- targetCol = table.ColumnModel.Columns[i];
- colIndex = i;
- break;
- }
- }
- if (colIndex == -1)
- {
- return;
- }
- if (targetCol is ImageColumn)
- {
- row.Cells[colIndex].Text = text;
- row.Cells[colIndex].Image = image;
- }
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "SetTableValueImage");
- }
- }
- public static object GetTableValue(Table table, int row, int col)
- {
- try
- {
- Column targetCol = null;
- int colIndex = -1;
- if (row < 0 || row >= table.TableModel.Rows.Count)
- {
- return null;
- }
- if (col < 0 || col >= table.ColumnModel.Columns.Count)
- {
- return null;
- }
- targetCol = table.ColumnModel.Columns[col];
- colIndex = col;
- if (colIndex == -1)
- {
- return null;
- }
- if (targetCol is TextColumn || targetCol is ComboBoxColumn || targetCol is ButtonColumn)
- {
- if (table.TableModel.Rows[row].Cells[colIndex].Text == null)
- {
- return "";
- }
- else
- {
- return table.TableModel.Rows[row].Cells[colIndex].Text;
- }
- }
- else if (targetCol is CheckBoxColumn)
- {
- return table.TableModel.Rows[row].Cells[colIndex].Checked;
- }
- else
- {
- return table.TableModel.Rows[row].Cells[colIndex].Data;
- }
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "GetTableValue");
- return null;
- }
- }
- public static string GetTableValueString(Table table, int row, int col)
- {
- try
- {
- Column targetCol = null;
- int colIndex = -1;
- if (row < 0 || row >= table.TableModel.Rows.Count)
- {
- return "";
- }
- if (col < 0 || col >= table.ColumnModel.Columns.Count)
- {
- return "";
- }
- targetCol = table.ColumnModel.Columns[col];
- colIndex = col;
- if (colIndex == -1)
- {
- return "";
- }
- if (targetCol is TextColumn || targetCol is ComboBoxColumn || targetCol is ButtonColumn)
- {
- if (table.TableModel.Rows[row].Cells[colIndex].Text == null)
- {
- return "";
- }
- else
- {
- return table.TableModel.Rows[row].Cells[colIndex].Text;
- }
- }
- else if (targetCol is CheckBoxColumn)
- {
- return table.TableModel.Rows[row].Cells[colIndex].Checked.ToString();
- }
- else
- {
- return table.TableModel.Rows[row].Cells[colIndex].Data.ToString();
- }
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "GetTableValueString");
- return "";
- }
- }
- public static object GetTableValue(Table table, int row, string colName)
- {
- try
- {
- Column targetCol = null;
- int colIndex = -1;
- if (row < 0 || row >= table.TableModel.Rows.Count)
- {
- return null;
- }
- for (int i = 0; i < table.ColumnModel.Columns.Count; i++)
- {
- if (table.ColumnModel.Columns[i].Text == colName)
- {
- targetCol = table.ColumnModel.Columns[i];
- colIndex = i;
- break;
- }
- }
- if (colIndex == -1)
- {
- return null;
- }
- if (targetCol is TextColumn || targetCol is ComboBoxColumn || targetCol is ButtonColumn)
- {
- if (table.TableModel.Rows[row].Cells[colIndex].Text == null)
- {
- return "";
- }
- else
- {
- return table.TableModel.Rows[row].Cells[colIndex].Text;
- }
- }
- else if (targetCol is CheckBoxColumn)
- {
- return table.TableModel.Rows[row].Cells[colIndex].Checked;
- }
- else
- {
- return table.TableModel.Rows[row].Cells[colIndex].Data;
- }
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "GetTableValue");
- return null;
- }
- }
- public static string GetTableValueString(Table table, int row, string colName)
- {
- try
- {
- Column targetCol = null;
- int colIndex = -1;
- if (row < 0 || row >= table.TableModel.Rows.Count)
- {
- return "";
- }
- for (int i = 0; i < table.ColumnModel.Columns.Count; i++)
- {
- if (table.ColumnModel.Columns[i].Text == colName)
- {
- targetCol = table.ColumnModel.Columns[i];
- colIndex = i;
- break;
- }
- }
- if (colIndex == -1)
- {
- return "";
- }
- if (targetCol is TextColumn || targetCol is ComboBoxColumn || targetCol is ButtonColumn)
- {
- if (table.TableModel.Rows[row].Cells[colIndex].Text == null)
- {
- return "";
- }
- else
- {
- return table.TableModel.Rows[row].Cells[colIndex].Text;
- }
- }
- else if (targetCol is CheckBoxColumn)
- {
- return table.TableModel.Rows[row].Cells[colIndex].Checked.ToString();
- }
- else
- {
- return table.TableModel.Rows[row].Cells[colIndex].Data.ToString();
- }
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "GetTableValueString");
- return "";
- }
- }
- public static Row GetTableRowByKey(ref Table table, string key)
- {
- try
- {
- foreach (Row row in table.TableModel.Rows)
- {
- if (row.Cells[0].Text == key)
- {
- return row;
- }
- }
- return null;
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "GetTableRowByKey");
- return null;
- }
- }
- public static int GetTableRowByKey(ref Table table, TableKey keys)
- {
- try
- {
- int i, j;
- int row = -1;
- int keyCount;
- keyCount = keys.Count;
- if (keyCount <= 0)
- {
- return -1;
- }
- for (i = 0; i < table.TableModel.Rows.Count; i++)
- {
- for (j = 0; j < keyCount; j++)
- {
- if (!object.Equals(GetTableValue(table, i, keys.GetKeyName(j)), keys.GetKeyValue(j)))
- {
- break;
- }
- }
- if (j == keyCount)
- {
- row = i;
- break;
- }
- }
- return row;
- }
- catch (System.Exception e)
- {
- GlobalFunction.MsgBoxException(e.Message, "GetTableRowByKey");
- return -1;
- }
- }
- public static int GetColumnIndexByName(Table table, string strColName)
- {
- try
- {
- if (table.ColumnModel.Columns.Count <= 0)
- {
- return -1;
- }
- else
- {
- for (int i = 0; i < table.ColumnModel.Columns.Count; i++)
- {
- if (table.ColumnModel.Columns[i].Text == strColName)
- {
- return i;
- }
- }
- return -1;
- }
- }
- catch (System.Exception ex)
- {
- GlobalFunction.MsgBoxException(ex.Message, "GetColumnIndexByName");
- return -1;
- }
- }
- public static void SetCellBackColor(ref Table table, int row, string strColName, Color color)
- {
- try
- {
- if (row >= table.TableModel.Rows.Count || row < 0)
- {
- return;
- }
- int col = GetColumnIndexByName(table, strColName);
- if (col == -1)
- {
- return;
- }
- table.TableModel.Rows[row].Cells[col].BackColor = color;
- }
- catch (System.Exception ex)
- {
- GlobalFunction.MsgBoxException(ex.Message, "SetCellBackColor");
- }
- }
- public static void SetRowBackColor(ref Table table, int row, Color color)
- {
- try
- {
- if (row >= table.TableModel.Rows.Count || row < 0)
- {
- return;
- }
- table.TableModel.Rows[row].BackColor = color;
- //for (int col = 0; col < table.ColumnModel.Columns.Count; col++)
- //{
- // table.TableModel.Rows[row].Cells[col].BackColor = color;
- //}
- }
- catch (System.Exception ex)
- {
- GlobalFunction.MsgBoxException(ex.Message, "SetRowBackColor");
- }
- }
- public static void SetCellForeColor(ref Table table, int row, string strColName, Color color)
- {
- try
- {
- if (row >= table.TableModel.Rows.Count || row < 0)
- {
- return;
- }
- int col = GetColumnIndexByName(table, strColName);
- if (col == -1)
- {
- return;
- }
- table.TableModel.Rows[row].Cells[col].ForeColor = color;
- }
- catch (System.Exception ex)
- {
- GlobalFunction.MsgBoxException(ex.Message, "SetCellForeColor");
- }
- }
- public static void SetRowForeColor(ref Table table, int row, Color color)
- {
- try
- {
- if (row >= table.TableModel.Rows.Count || row < 0)
- {
- return;
- }
- table.TableModel.Rows[row].ForeColor = color;
- //for (int col = 0; col < table.ColumnModel.Columns.Count; col++)
- //{
- // table.TableModel.Rows[row].Cells[col].ForeColor = color;
- //}
- }
- catch (System.Exception ex)
- {
- GlobalFunction.MsgBoxException(ex.Message, "SetRowForeColor");
- }
- }
- public static void SetColumnBackColor(ref Table table, string strColName, Color color)
- {
- try
- {
- if (table.TableModel.Rows.Count <= 0)
- {
- return;
- }
- int col = GetColumnIndexByName(table, strColName);
- if (col == -1)
- {
- return;
- }
- foreach (Row row in table.TableModel.Rows)
- {
- row.Cells[col].BackColor = color;
- }
- }
- catch (System.Exception ex)
- {
- GlobalFunction.MsgBoxException(ex.Message, "SetColumnBackColor");
- }
- }
- public static void SetColumnForeColor(ref Table table, string strColName, Color color)
- {
- try
- {
- if (table.TableModel.Rows.Count <= 0)
- {
- return;
- }
- int col = GetColumnIndexByName(table, strColName);
- if (col == -1)
- {
- return;
- }
- foreach (Row row in table.TableModel.Rows)
- {
- row.Cells[col].ForeColor = color;
- }
- }
- catch (System.Exception ex)
- {
- GlobalFunction.MsgBoxException(ex.Message, "SetColumnForeColor");
- }
- }
- public static void SelectRow(ref Table table, int rowIndex)
- {
- try
- {
- if (rowIndex >= 0 && rowIndex < table.TableModel.Rows.Count)
- {
- table.TableModel.Selections.SelectCells(rowIndex, 0, rowIndex, table.ColumnModel.Columns.Count - 1);
- }
- }
- catch (System.Exception ex)
- {
- GlobalFunction.MsgBoxException(ex.Message, "SelectRow");
- }
- }
- public static void Sort(ref Table table, string strColName, SortOrder order, bool stable)
- {
- try
- {
- if (table.TableModel.Rows.Count <= 0)
- {
- return;
- }
- int col = GetColumnIndexByName(table, strColName);
- if (col == -1)
- {
- return;
- }
- else
- {
- table.Sort(col, order, stable);
- }
- }
- catch (System.Exception ex)
- {
- GlobalFunction.MsgBoxException(ex.Message, "Sort");
- }
- }
- }
- }
.Net强大的列表控件XPTable [转]的更多相关文章
- Github上star数超1000的Android列表控件
		Android开发中,列表估计是最最常使用到的控件之一了.列表相关的交互如下拉刷新,上拉更多,滑动菜单,拖动排序,滑动菜单,sticky header分组,FAB等等都是十分常见的体验.Github中 ... 
- UWP开发必备:常用数据列表控件汇总比较
		今天是想通过实例将UWP开发常用的数据列表做汇总比较,作为以后项目开发参考.UWP开发必备知识点总结请参照[UWP开发必备以及常用知识点总结]. 本次主要讨论以下控件: GridView:用于显示数据 ... 
- .NET各大平台数据列表控件绑定原理及比较(WebForm、Winform、WPF)
		说说WebForm: 数据列表控件: WebForm 下的列表绑定控件基本就是GridView.DataList.Repeater:当然还有其它DropDownList.ListBox等. 它们的共同 ... 
- WPF自定义控件与样式(7)-列表控件DataGrid与ListView自定义样式
		一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: Dat ... 
- Flex 列表控件中的操作
		主要操作包括:显示提示,使用图标,编辑列表条目中数据. 1.使用数据提示: 当鼠标停留在条目上时,可以显示该条目的相关数据提示. 当利用滚动条时,可以显示滚动条的相关提示. 在列表控件中使用showD ... 
- cocos2dx实现功能强大的RichText控件
		转自:http://blog.csdn.net/ljxfblog/article/details/26136773 最近准备做一个聊天系统,开始准备使用cocos2dx的UIRichText控件来显示 ... 
- VC++ 列表控件的使用方法
		列表控件可以看作是功能增强的ListBox,它提供了四种风格,而且可以同时显示一列的多中属性值.MFC中使用CListCtrl类来封装列表控件的各种操作. 通过调用BOOL Create( DWORD ... 
- 【WPF开发备忘】使用MVVM模式开发中列表控件内的按钮事件无法触发解决方法
		实际使用MVVM进行WPF开发的时候,可能会用到列表控件中每行一个编辑或删除按钮,这时直接去绑定,发现无法响应: <DataGridTemplateColumn Header="操作& ... 
- Android自定义标签列表控件LabelsView解析
		版权声明:本文为博主原创文章,未经博主允许不得转载. 无论是在移动端的App,还是在前端的网页,我们经常会看到下面这种标签的列表效果: 标签从左到右摆放,一行显示不下时自动换行.这样的效果用And ... 
随机推荐
- 安装JDK以及配置Java运行环境
			安装JDK以及配置Java运行环境 1.JDK下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2 ... 
- java 复习整理(五 类加载机制与对象初始化)
			类加载机制与对象初始化 一 . 类加载机制 类加载机制是指.class文件加载到jvm并形成Class对象的机制.之后应用可对Class对象进行实例化并调用.类加载机制可在运行时动态加载外部的类, ... 
- 转:android service总结
			1.Service的种类 按运行地点分类: 类别 区别 优点 缺点 应用 本地服务(Local) 该服务依附在主进程上, 服务依附在主进程上而不是独立的进程,这样在一定程度上节约了资源,另 ... 
- SpringMVC+MyBatis+Shiro 配置文件详解
			1.web.xml文件的配置 <?xml version="1.0" encoding="UTF-8"?> <web-app version= ... 
- 结构型设计模式之桥接模式(Bridge)
			结构 意图 将抽象部分与它的实现部分分离,使它们都可以独立地变化. 适用性 你不希望在抽象和它的实现部分之间有一个固定的绑定关系.例如这种情况可能是因为,在程序运行时刻实现部分应可以被选择或者切换. ... 
- lxml.html删除节点树和tag对
			# encoding: utf-8import StringIO from apihelper import info, info_savefrom lxml import etree, htmlfr ... 
- ScrollView下嵌套GridView或ListView默认不在顶部的解决方法
			自定义ScrollView重写下面的方法 /* ScrollView下嵌套GridView或ListView默认不在顶部的解决方法*/ @Override protected int computeS ... 
- how to configure team on liunx(RHEL7.x/Centos7.x)
			#install team sofeware yum install teamd -y #check team configuration nmcli con show #Next we create ... 
- 修改 Lua支持中文变量名
			1. 找到 LuaPlus 工程下的 Lua Source Files 下的 llex.c: 2. 在该文件中找到下面所列函数: static int llex (LexState *ls, Se ... 
- hdu 5086(递推)
			Revenge of Segment Tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ... 
