1.引入ObjectListView.dll
2.使用
把objectlistview拖入到窗体
加入列,
objectlistview显示数据必须要和一个对象绑定,objectListView1.SetObjects(object);
而每一列的显示对应一个成员变量
aspectName必须与object的成员变量Title关联,才可以显示出数据,所以,aspectName栏必须填入Title。
加入过程:
MyObject myObject = new MyObject();
myObject.nameString = "yrf";
myObject.ageString = "12";
List<MyObject> list = new List<MyObject>();
list.Add(myObject);
objectListView1.SetObjects(list);
是否显示组:
this.olvComplex.ShowGroups = false;
当鼠标放在某一行,颜色会改变的效果
this.olvSimple.UseHotItem = true;
this.olvSimple.HotItemStyle = this.hotItemStyle1;
OLVColumn增加一列,表格中的一列
olvJokeColumn
加入图片
1.ObjectListView‘s SmallImageList
2.
this.titleColumn.ImageGetter = delegate (object rowObject) {
Song s = (Song)rowObject;
if (s.Rating >= 80)
return "star";
else
return "song";
};
加入checkbox:
1.this.olvComplex.OwnerDraw = true;
2.this.olvComplex.UseSubItemCheckBoxes = true;
3.this.olvJokeColumn.CheckBoxes = true;
4.响应事件:SubItemChecking
改变某一列的颜色和字体:
To change the formatting of an individual cell, you need to setUseCellFormatEvents totrue and then listen forFormatCell events.To show just the credit balance in red, you could do something like this:
private void olv1_FormatCell(object sender, FormatCellEventArgs e) {
if (e.ColumnIndex == this.creditBalanceColumn.Index) {
Customer customer = (Customer)e.Model;
if (customer.Credit < 0)
e.SubItem.ForeColor = Color.Red;
}
}
行高:
RowHeight
去掉头部:
headstyle
改变头部样式:
Make sure HeaderUsesThemes is false
HeaderFormatStyle
点击行事件的响应:
1.Click事件
2.objectListView1.HotRowIndex
改变表格头部的颜色:
The colours used to indicate a selected row are governed by the operating system andcannot be changed. However, if you set UseCustomSelectionColors to true, theObjectListView will use HighlightBackgroundColor and HighlightForegroundColor asthe colours for the selected rows.