473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Divider in ListView

Hi,
I've got a list view that displays a series of images. I'd like to be
able to draw a divider across the list view to divide the images into
groups. Ideally, I'd have a group name, with a line underneath it that
spans the ListView. How could this be done? I tried using an image as
the divider, but it forced the divider image to be the same size as
the image size used for the ImageList that stores the images for the
ListView.
Jun 27 '08 #1
8 5748
ListView supports groups on XP and above, see below. Let me know if I
have misunderstood.

Marc

using System;
using System.Drawing;
using System.Windows.Forms;
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
using(Form form = new Form())
using (ListView lv = new ListView())
{
ImageList list = new ImageList();
list.Images.Add("a", SystemIcons.Application);
list.Images.Add("b", SystemIcons.Asterisk);
list.Images.Add("c", SystemIcons.Shield);
list.Images.Add("d", SystemIcons.Error);
list.Images.Add("e", SystemIcons.Information);
lv.View = View.LargeIcon;
lv.LargeImageList = list;
ListViewGroup foo = lv.Groups.Add("foo", "Foo Group"),
bar = lv.Groups.Add("bar", "Bar Group");
lv.Items.Add("Item 1", "a").Group = foo;
lv.Items.Add("Item 2", "b").Group = bar;
lv.Items.Add("Item 3", "c").Group = foo;
lv.Items.Add("Item 4", "d").Group = foo;
lv.Items.Add("Item 5", "e").Group = bar;
lv.Dock = DockStyle.Fill;
form.Controls.Add(lv);
Application.Run(form);

}
}
}
Jun 27 '08 #2
On Jun 18, 2:25*am, Marc Gravell <marc.grav...@gmail.comwrote:
ListView supports groups on XP and above, see below. Let me know if I
have misunderstood.

Marc

using System;
using System.Drawing;
using System.Windows.Forms;
static class Program
{
* * [STAThread]
* * static void Main()
* * {
* * * * Application.EnableVisualStyles();
* * * * using(Form form = new Form())
* * * * using (ListView lv = new ListView())
* * * * {
* * * * * * ImageList list = new ImageList();
* * * * * * list.Images.Add("a", SystemIcons.Application);
* * * * * * list.Images.Add("b", SystemIcons.Asterisk);
* * * * * * list.Images.Add("c", SystemIcons.Shield);
* * * * * * list.Images.Add("d", SystemIcons.Error);
* * * * * * list.Images.Add("e", SystemIcons.Information);
* * * * * * lv.View = View.LargeIcon;
* * * * * * lv.LargeImageList = list;
* * * * * * ListViewGroup foo = lv.Groups.Add("foo", "Foo Group"),
* * * * * * * * bar = lv.Groups.Add("bar", "Bar Group");
* * * * * * lv.Items.Add("Item 1", "a").Group = foo;
* * * * * * lv.Items.Add("Item 2", "b").Group = bar;
* * * * * * lv.Items.Add("Item 3", "c").Group = foo;
* * * * * * lv.Items.Add("Item 4", "d").Group = foo;
* * * * * * lv.Items.Add("Item 5", "e").Group = bar;
* * * * * * lv.Dock = DockStyle.Fill;
* * * * * * form.Controls.Add(lv);
* * * * * * Application.Run(form);

* * * * }
* * }

}
I trhink that will do what I want, but I'm running into problems, as
my listview is in virtual mode. The following code:

ListViewGroup foo = new ListViewGroup("fg", "Foo Group");
gallery.Groups.Insert(0, foo);

gives an InvalidOperationException when I try to do the insert:

"When the ListView is in virtual mode, you cannot enumerate through
the ListView items collection using an enumerator or call
GetEnumerator. Use the ListView items indexer instead and access an
item by index value."

This is occurring in my CacheVirtualItems handler method, when I
attempt to add items to my cache and also add them to the group.
Jun 27 '08 #3
According to some (an example below) groups aren't supported in virtual
mode. This wouldn't surprise me, thinking about how it would need to
allocate space per group...

Sorry...

http://blogs.msdn.com/cumgranosalis/...ViewUsage.aspx
Jun 27 '08 #4
On Jun 19, 3:31*am, Marc Gravell <marc.grav...@gmail.comwrote:
According to some (an example below) groups aren't supported in virtual
mode. This wouldn't surprise me, thinking about how it would need to
allocate space per group...

Sorry...

http://blogs.msdn.com/cumgranosalis/...VirtualListVie...
Hmmm ok... can anyone think of a way to fake it? The reason I went to
using virtual mode with my list view is that the list view displays
large collections of images. The image files themselves usually come
from digital cameras and usually are 1-5 MB. Loading them all and
displaying thumbnails was rather slow. Things seem better in virtual
mode, but now I'd like to get groups working to group the images (the
user can select from predefined grouping criteria).

I'm open to creative or unorthodox solutions to try, but I'm not yet
familiar enough with .NET to know which direction to start in.

One idea I had was to force Windows to generate/update a Thumbs.db
file in the directory that contains the images and then just read
that, but I haven't yet found a way to do this. Is it even possible?
Jun 27 '08 #5
How about you just add the filenames first, and then load the images
on a background thread, using Control.BeginInvoke when you have an
image ready; back on the UI thread, add the image to the image list
and set the index/key of the image against the item?

Marc
Jun 27 '08 #6
On Jun 19, 4:44*pm, Marc Gravell <marc.grav...@gmail.comwrote:
How about you just add the filenames first, and then load the images
on a background thread, using Control.BeginInvoke when you have an
image ready; back on the UI thread, add the image to the image list
and set the index/key of the image against the item?

Marc
Ok, I've got something that sort of works now... I have a
BackgroundWorker that will load the images into a new ImageList and
then returns that to the main thread (which then overwrites the
original imageList with the new one) - is there a way to get the
background worker to modify the original ImageList? All my research so
far indicates "probably not" but I'm not sure (or I wouldn't have
asked).

There's another problem I have with the debugger:
When I run without the debugger, the app works fine and the images get
loaded. When I run WITH the debugger, the images do NOT load, and
every item in the ListView just displays the "loading" image that they
all start with by default. I have no idea why this happens. Can anyone
explain this, and maybe a workaround?
Jun 27 '08 #7
I would imagine that once you have loaded each image you can just use
something like:

// runs on worker thread
// .. load an image
this.Invoke((MethodInvoker) delegate {
// runs on UI thread
// add the image
imagelist.Images.Add(key, image);
// assign keys...
});
// runs on worker thread
// .. load the next image

Marc
Jun 27 '08 #8
On Jun 20, 4:34*am, Marc Gravell <marc.grav...@gmail.comwrote:
I would imagine that once you have loaded each image you can just use
something like:

// runs on worker thread
// .. load an image
this.Invoke((MethodInvoker) delegate {
* *// runs on UI thread
* *// add the image
* *imagelist.Images.Add(key, image);
* *// assign keys...});

// runs on worker thread
// .. load the next image

Marc
Thanks, that helped!
What I ultimately ended up with (in the body of my background worker's
doWork handler):

//for every filename in a list of filenames:
{
//del delegate will actually load the images into memory and
manipulate them
//into thumbnails when appropriate...
IAsyncResult ar = del.BeginInvoke(name, null, null);
//...and return the thumbnails here:
Image thumb = del.EndInvoke(ar);
string key = getKeyForFileName(name);
//pass the new thumbnail into the updater, which will update
//the image list on UI.
this.Invoke(updaterDel, key,thumb);
}

At first I did the image loading AND the updating from this.Invoke,
but the UI would be blocked until all images were loaded (that
behaviour is what started me to look at virtual mode in the first
place, way back), so I had the delegate load the image seperately,
then return it to the main thread to update the UI. I'm sure this code
can be cleaned up some more, but at least I have something working for
now. Clean up to come in the morning when I'm fresh!
Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Anushya | last post by:
Hi I am using Listview and inherited listview control overriding WndProc & PreProcessMessage in ListView. I need this to customize listview to display only the page the user scrolls to. Since i...
7
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override...
3
by: Lucas Tam | last post by:
Is there a divider control in VB.NET similar to a Horizontal Line in HTML? In the About Box of VS.NET, there is a divider line at the bottom of the page. -- Lucas Tam (REMOVEnntp@rogers.com)...
11
by: Tarren | last post by:
Hi: How would I place a divider on the form where it looks chiseled and thin line - they are everywhere in Windows Apps, but cannot find the control to put on the form. Thanks
9
by: Kevin Westhead | last post by:
Can anyone confirm whether or not there are any limits imposed on the widths of autosized columns in a list-view. I've found that the autosizing appears to have an upper limit, i.e. it will not...
7
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
2
by: Jim Lewis | last post by:
Anyone know how to create a draggable divider between two Tkinter windows?
1
by: Borges | last post by:
Hi folks, I've got a listview with several columns, and I'm trying to automatically resize the columns when the control gets painted. I know there are methods for this in .NET 2 but we're not...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.