very stupid listview icon problem!

G

giddy

hi,

I have a listview on a form, the View is set to Tile. I also have an
image list tied to the *smallImageList property, i have one image in
the image list, its a png : 32X32


When i do this, i dont see an icon and the SubItem text!

lstvUsers.Columns.Add(Privilege");//added only so the tile detail is
visible
foreach (User _user in _users.Users)
{
ListViewItem lstviUser = new
ListViewItem(_user.Username,"User.png");
lstviUser.SubItems.Add(_user.Privilege.ToString());
lstvUsers.Items.Add(lstviUser);
}


When i added my imagelist to the largeImageList property the icon
shows up. BUT I still dont see the subitem text!? What am i doing
wrong!!!!

Gideon
 
G

Guest

If you are using a small image list to hold your icons you should set the
view property to SmallIcon. Similary if you want to use a large image list,
set the view property to LargeIcon. When you add items to your list view,
specify the index of the image from the image list to use for that item:

listView1.Columns.Add("Privilege");

System.Drawing.Icon myIcon = new System.Drawing.Icon("Icon1.ico");
ImageList myImageList = new ImageList();
myImageList.Images.Add(myIcon);
listView1.SmallImageList = myImageList;

for (int i = 0; i < 5; i++)
{
listView1.Items.Add(i.ToString(), 0);
}

http://msdn2.microsoft.com/en-us/li...imagelist(VS.71).aspx#Mtps_DropDownFilterText


Adrian.
 
G

Guest

I forgot to mention that you should create columns for each sub item that
you are adding to a list view item. If you set the view property of the list
view to Details you should be able to see all the data that you have added to
the list view.

listView1.Columns.Add("Privilege");
listView1.Columns.Add("Details");

System.Drawing.Icon myIcon = new System.Drawing.Icon("Icon1.ico");
ImageList myImageList = new ImageList();
myImageList.Images.Add(myIcon);
listView1.SmallImageList = myImageList;

for (int i = 0; i < 5; i++)
{
ListViewItem lstviUser = new ListViewItem(i.ToString(),0);
lstviUser.SubItems.Add(i.ToString() + " S");
listView1.Items.Add(lstviUser);
}


Adrian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top