ListView使用详解
2011-09-06 18:19
232 查看
listview 添加多个子项(带图标)
lstViewShow.GridLines = true;//显示行与行之间的分隔线lstViewShow.FullRowSelect = true;//要选择就是一行
lstViewShow.View = View.Details;//定义列表显示的方式
lstViewShow.Scrollable = true;//需要时候显示滚动条
lstViewShow.MultiSelect = false; // 不可以多行选择
lstViewShow.HeaderStyle = ColumnHeaderStyle.Clickable;
lstViewShow.Columns.Add("第一列", 100, HorizontalAlignment.Center);//第一个参数,表头名,第2个参数,表头大小
lstViewShow.Columns.Add("第二列", 100, HorizontalAlignment.Center);
lstViewShow.Columns.Add("第三列", 100, HorizontalAlignment.Center);
lstViewShow.Visible = true;//lstView可见
llstViewShow.SmallImageList = imageList1;
for(int I=0;I<=15;I++)
{
ListViewItem lvi = new ListViewItem(new string[]{"aaaaa","bbbb","cccc","dddd","eeee","ffff","gggg","hhhh"});
lvi.ImageIndex = I;
lstViewShow.Items.Add(lvi);
}
C#中ListView添加系统文件图标
using System.Runtime.InteropServices;public static uint SHGFI_ICON = 0x100;
public static uint SHGFI_DISPLAYNAME = 0x200;
public static uint SHGFI_TYPENAME = 0x400;
public static uint SHGFI_ATTRIBUTES = 0x800;
public static uint SHGFI_ICONLOCATION = 0x1000;
public static uint SHGFI_EXETYPE = 0x2000;
public static uint SHGFI_SYSICONINDEX = 0x4000;
public static uint SHGFI_LINKOVERLAY = 0x8000;
public static uint SHGFI_SELECTED = 0x10000;
public static uint SHGFI_LARGEICON = 0x0;
public static uint SHGFI_SMALLICON = 0x1;
public static uint SHGFI_OPENICON = 0x2;
public static uint SHGFI_SHELLICONSIZE = 0x4;
public static uint SHGFI_PIDL = 0x8;
public static uint SHGFI_USEFILEATTRIBUTES = 0x10;
public static uint FILE_ATTRIBUTE_NORMAL = 0x80;
public static uint LVM_FIRST = 0x1000;
public static uint LVM_SETIMAGELIST = LVM_FIRST + 3;
public static uint LVSIL_NORMAL = 0;
public static uint LVSIL_SMALL = 1;
[DllImport("Shell32.dll")]
public static extern IntPtr SHGetFileInfo(string pszPath,
uint dwFileAttributes, ref SHFILEINFO psfi,
int cbfileInfo, uint uFlags);
public struct SHFILEINFO
{
public IntPtr hIcon;
public int iIcon;
public int dwAttributes;
public string szDisplayName;
public string szTypeName;
}
[DllImport("User32.DLL")]
public static extern int SendMessage(IntPtr hWnd,
uint Msg, IntPtr wParam, IntPtr lParam);
public void ListViewSysImages(ListView AListView)
{
SHFILEINFO vFileInfo = new SHFILEINFO();
IntPtr vImageList = SHGetFileInfo("", 0, ref vFileInfo,
Marshal.SizeOf(vFileInfo), SHGFI_SHELLICONSIZE |
SHGFI_SYSICONINDEX | SHGFI_LARGEICON);
SendMessage(AListView.Handle, LVM_SETIMAGELIST, (IntPtr)LVSIL_NORMAL,
vImageList);
vImageList = SHGetFileInfo("", 0, ref vFileInfo,
Marshal.SizeOf(vFileInfo), SHGFI_SHELLICONSIZE |
SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
SendMessage(AListView.Handle, LVM_SETIMAGELIST, (IntPtr)LVSIL_SMALL,
vImageList);
}
public int FileIconIndex(string AFileName)
{
SHFILEINFO vFileInfo = new SHFILEINFO();
SHGetFileInfo(AFileName, 0, ref vFileInfo,
Marshal.SizeOf(vFileInfo), SHGFI_SYSICONINDEX);
return vFileInfo.iIcon;
}
private void button1_Click(object sender, EventArgs e)
{
ListViewSysImages(listView1);
listView1.Items.Add("temp.txt", FileIconIndex(@"c:/temp/temp.txt"));
}
相关文章推荐
- ListView嵌套GridView使用详解
- Android PullToRefresh (ListView GridView 下拉刷新) 使用详解
- android ListView使用详解&事例
- Android研究之手PullToRefresh(ListView GridView 下拉刷新)使用详解
- 关于开源项目SwipeMenuListView的使用详解
- Android PullToRefresh (ListView GridView 下拉刷新) 使用详解
- Android 仿QQ好友分组列表、ExpandableListView的使用详解
- RecyclerView使用详解(代替ListView)
- Android列表组件ListView使用详解之设置分割线
- Android中ExpandableListView使用示例详解
- Pull To Refresh (ListView GridView 下拉刷新) 使用详解
- 关于Android中listView的复用及优化问题详解,应用开发者应多多使用,是app更顺畅,让用户更好体验!
- ListView嵌套GridView使用详解
- ListView使用详解,listActivity使用方法
- Android PullToRefresh (ListView GridView 下拉刷新) 使用详解
- Android ListView使用详解
- Android PullToRefresh (ListView GridView 下拉刷新) 使用详解
- Android PullToRefresh (ListView GridView 下拉刷新) 使用详解 Hongyang 转载
- ListView 使用方法详解
- Android PullToRefresh (ListView GridView 下拉刷新) 使用详解