当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 实现ListView控件的行间隔颜色的优化代码

ASP.NET
Asp.net利用JQuery弹出层加载数据代码
asp.net dataview做无限极分类的又一用法
asp.net ckeditor编辑器的使用方法
告别ADO.NET实现应用系统无缝切换的烦恼(总结篇)
asp.net 实现动态显示当前时间(不用javascript不考虑开销)
.net动态显示当前时间(客户端javascript)
asp.net 结合YUI 3.0小示例
asp.net 取消缓存相关问题说明
asp.net 计划任务管理程序实现,多线程任务加载
ASP.NET 跨页面传值方法
asp.net中url地址传送中文参数时的两种解决方案
Asp.net 菜单控件简洁版
asp.net jQuery Ajax用户登录功能的实现
asp.net SharpZipLib的压缩与解压问题
asp.net url重写后页面回传问题
asp.net与Discuz!NT整合集成实例教程
Discuz!NT 3与asp.net 整合的实例教程
测试控制台使用方法
.net 动态标题实现方法
asp.net *.ashx类型的文件使用说明

ASP.NET 中的 实现ListView控件的行间隔颜色的优化代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 51 ::
收藏到网摘: n/a

崔占民在其文章《用代码实现ListView控件的行间隔颜色》中给出了实现代码,经过笔者测试,发现有如下bug:
首先,虽然可以看到背景色间隔,但是条块的高度等于原始picGreenBar的高度。应该在autoredraw属性设置为true之前,将height属性设置为一个最小值,比如1。
另外,listview的属性要修改一下: ... ListView1.View = lvwReport ListView1.FullRowSelect = True ListView1.GridLines = True picGreenbar.Height = 1 '添加一些实验数据 ....
为方便读者,将全部代码公布如下(关键代码来自《用代码实现ListView控件的行间隔颜色》):
--------------------------------
VERSION 5.00Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"Begin VB.Form Form1 Caption = "Form1" ClientHeight = 5400 ClientLeft = 60 ClientTop = 345 ClientWidth = 5940 LinkTopic = "Form1" ScaleHeight = 5400 ScaleWidth = 5940 StartUpPosition = 3
Begin VB.PictureBox picGreenbar Height = 1695 Left = 120 ScaleHeight = 1282.353 ScaleMode = 0 'User ScaleWidth = 4635 TabIndex = 1 Top = 3480 Width = 4695 End Begin MSComctlLib.ListView ListView1 Height = 3255 Left = 120 TabIndex = 0 Top = 120 Width = 4695 _ExtentX = 8281 _ExtentY = 5741 View = 3 Sorted = -1 'True LabelWrap = -1 'True HideSelection = -1 'True FlatScrollBar = -1 'True FullRowSelect = -1 'True GridLines = -1 'True _Version = 393217 ForeColor = -2147483640 BackColor = -2147483643 BorderStyle = 1 Appearance = 1 NumItems = 0 EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption Explicit

Private Sub Form_Load()
Dim j As Integer Dim itmX As ListItem ListView1.ColumnHeaders.Add , , "This is Just a Simple Example" ListView1.ColumnHeaders(1).Width = 3000 ListView1.View = lvwReport ListView1.FullRowSelect = True ListView1.GridLines = True picGreenbar.Height = 1 '添加一些实验数据 For j = 1 To 33 Set itmX = ListView1.ListItems.Add() itmX.Text = "This is item number " & CStr(j) Next j Call ColorListView(Me.ListView1, Me.picGreenbar)
End Sub
Private Sub Form_Resize() ListView1.Width = Me.ScaleWidthEnd SubPrivate Sub ColorListView(ListView1 As ListView, picGreenbar As PictureBox) Dim i As Integer Dim iFontHeight As Long Dim iBarHeight As Integer Dim ColHead As ColumnHeader Me.ScaleMode = vbTwips picGreenbar.ScaleMode = vbTwips picGreenbar.BorderStyle = vbBSNone picGreenbar.AutoRedraw = True picGreenbar.Visible = False picGreenbar.Font = ListView1.Font iFontHeight = picGreenbar.TextHeight("b") + Screen.TwipsPerPixelY iBarHeight = (iFontHeight * 1) picGreenbar.Width = ListView1.Width '====== picGreenbar.Height = iBarHeight * 2 picGreenbar.ScaleMode = vbUser picGreenbar.ScaleHeight = 2 picGreenbar.ScaleWidth = 1 'draw the actual bars picGreenbar.Line (0, 0)-(1, 1), &HE7E8FC, BF picGreenbar.Line (0, 1)-(1, 2), RGB(0, 255, 0), BF '====== ListView1.PictureAlignment = lvwTile ListView1.Picture = picGreenbar.ImageEnd Sub