473,683 Members | 3,080 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5775
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.Ena bleVisualStyles ();
using(Form form = new Form())
using (ListView lv = new ListView())
{
ImageList list = new ImageList();
list.Images.Add ("a", SystemIcons.App lication);
list.Images.Add ("b", SystemIcons.Ast erisk);
list.Images.Add ("c", SystemIcons.Shi eld);
list.Images.Add ("d", SystemIcons.Err or);
list.Images.Add ("e", SystemIcons.Inf ormation);
lv.View = View.LargeIcon;
lv.LargeImageLi st = list;
ListViewGroup foo = lv.Groups.Add(" foo", "Foo Group"),
bar = lv.Groups.Add(" bar", "Bar Group");
lv.Items.Add("I tem 1", "a").Group = foo;
lv.Items.Add("I tem 2", "b").Group = bar;
lv.Items.Add("I tem 3", "c").Group = foo;
lv.Items.Add("I tem 4", "d").Group = foo;
lv.Items.Add("I tem 5", "e").Group = bar;
lv.Dock = DockStyle.Fill;
form.Controls.A dd(lv);
Application.Run (form);

}
}
}
Jun 27 '08 #2
On Jun 18, 2:25*am, Marc Gravell <marc.grav...@g mail.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.Ena bleVisualStyles ();
* * * * using(Form form = new Form())
* * * * using (ListView lv = new ListView())
* * * * {
* * * * * * ImageList list = new ImageList();
* * * * * * list.Images.Add ("a", SystemIcons.App lication);
* * * * * * list.Images.Add ("b", SystemIcons.Ast erisk);
* * * * * * list.Images.Add ("c", SystemIcons.Shi eld);
* * * * * * list.Images.Add ("d", SystemIcons.Err or);
* * * * * * list.Images.Add ("e", SystemIcons.Inf ormation);
* * * * * * lv.View = View.LargeIcon;
* * * * * * lv.LargeImageLi st = list;
* * * * * * ListViewGroup foo = lv.Groups.Add(" foo", "Foo Group"),
* * * * * * * * bar = lv.Groups.Add(" bar", "Bar Group");
* * * * * * lv.Items.Add("I tem 1", "a").Group = foo;
* * * * * * lv.Items.Add("I tem 2", "b").Group = bar;
* * * * * * lv.Items.Add("I tem 3", "c").Group = foo;
* * * * * * lv.Items.Add("I tem 4", "d").Group = foo;
* * * * * * lv.Items.Add("I tem 5", "e").Group = bar;
* * * * * * lv.Dock = DockStyle.Fill;
* * * * * * form.Controls.A dd(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 InvalidOperatio nException 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 CacheVirtualIte ms 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...@g mail.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.BeginIn voke 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...@g mail.comwrote:
How about you just add the filenames first, and then load the images
on a background thread, using Control.BeginIn voke 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
BackgroundWorke r 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((Me thodInvoker) delegate {
// runs on UI thread
// add the image
imagelist.Image s.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...@g mail.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((Me thodInvoker) delegate {
* *// runs on UI thread
* *// add the image
* *imagelist.Imag es.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(a r);
string key = getKeyForFileNa me(name);
//pass the new thumbnail into the updater, which will update
//the image list on UI.
this.Invoke(upd aterDel, 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
2625
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 am populating listview with more than 200,000 items. It is too slow and tried virtual listview. But that doesnot allow me to add images in the listview. So now trying to list only the page user scrolls to.
7
6441
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 ListView.Items.Add(), . I see that it is a virtual method so it should be easy to do. If anyone can help I would appreciate it greatly. I can do what I need to do in a different way this would just make everything significantly cleaner and eaasier...
3
8354
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) Please delete "REMOVE" from the e-mail address when replying. http://members.ebay.com/aboutme/coolspot18/
11
8406
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
10373
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 expand beyond some (unknown) maximum length. This applies to user-autosizing (double-clicking the divider) and code-autosizing using LVSCW_AUTOSIZE. For example, create a new project and place a ListView (VB5 version) and CommandButton on a form...
7
14990
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 MyList data is resident in a dataset table. I'm stuck and can't choose either because. If I choose ListView as my control I don't understand how to programmatically get the data from the dataset table
2
3781
by: Jim Lewis | last post by:
Anyone know how to create a draggable divider between two Tkinter windows?
1
3358
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 using it yet, so I've gotta get it working the old-fashioned way. There's built-in functionality for this already. If the user double-clicks on a coumn divider the listview control auto resizes the column nicely. I'm just trying to do the same...
4
4508
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 is that when clicking on the "Show details" button the ListView for the appropriate row binds in the codebehind and displays the detail data for the selected row. I did something similar with a gridview control previously, but want to be able to...
0
8504
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8922
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8753
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8771
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7582
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5789
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2934
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.