ObjectListView的使用

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.



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
ObjectListView1是一个ListView控件的扩展,用于显示和操作对象的列表数据。它包括一些常用的功能,如添加、删除、排序和过滤行。可以使用RemoveObject方法从ListView中删除一行,例如objectListView1.RemoveObject(dataList)。要显示数据,需要将数据对象与ObjectListView绑定,可以使用SetObjects方法,例如objectListView1.SetObjects(object)。此外,还可以使用TypedObjectListView来获取绑定对象,无需进行类型强转,使用方法很简单,先将普通的ObjectListView对象包装成一个TypedObjectListView对象,之后需要获取绑定对象时,使用TypedObjectListView对象即可,例如TypedObjectListView typedObjectListView1=new TypedObjectListView<Person>(this.objectListView1)。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [ObjectListView 使用技巧](https://blog.csdn.net/csdnharrychinese/article/details/120735900)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [ObjectListView使用](https://blog.csdn.net/a2657222/article/details/8393898)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值