List View
58K views
Nov 21, 2023
List View
View Video Transcript
0:00
In this video we are going to see how to use a list view control in a Windows Forms application using Visual Studio 2010
0:08
Before we start, I assume you already have a Visual Studio 2010 installed in a machine
0:14
So open fire up your Visual Studio 2010 and create a Windows Forms application
0:20
Once your application is created, now you simply go to Toolbox and drag and drop a List View control from Toolbox onto the form
0:29
form. After control is added to the form you can resize it, relocate it
0:36
it, wherever you want to move it. And then next thing we are going to do is create a
0:42
set its properties. Right click on the control and hit properties. As you can see, the
0:49
properties window pops up here. First thing I'm going to do is change the name. I'm going to change the name. I'm going to change
0:58
name to author's list view now list view is no different than any other
1:05
controls available in Windows forms except it has some extra features if one
1:11
other thing I want to mention before we go further if you are just looking for
1:16
a control that just lists some items and you can sort them and move around
1:21
select them I would recommend you go to list box control do not use list view
1:27
control. This view control is much more complex and it's more useful when you're
1:32
trying to display complex items such as you know some items may have images
1:39
some items may have different views, the same items can also be you know
1:44
different they may have different images then you can also probably say group
1:49
those items based on different categories and things like that so what I
1:55
would recommend if you just need a simple listing or item to be listed in a control
2:00
I suggest you go back to your list box control and try to use that So let get back to our list view control So as you can see from properties we can set all the properties from here
2:12
You can, you know, set border style. You can set any other properties from here
2:19
And you can also set context menu columns. If you want to add multiple columns, you can also do that
2:28
So as soon as you click on columns, you will see column header collection
2:32
editor pops up here you can say add different columns where name of the headroom
2:37
is column header one I'm going to change that to name header if you look at
2:48
here the column header also has a text you can change the text to say name or say
3:00
author name and you can align it obviously with add another say all right so we add three
3:27
all right so we added three columns now now let's go back to items property
3:36
items property actually adds items to a list view control now there can be
3:43
different ways you can add items so first before we go to go into more
3:47
details let's just add few items in first we are going to add simple tax items
3:51
simple strings so if you click on items you will see list view collection
3:56
list view item collection editor appears so add as soon as you add you'll see list view item
4:03
is added where a list view item can have its own properties can have its own background
4:08
color it can have its own font everything it can have whatever you want In text say you can have tool tip for text you can also assign some groups images which I going to discuss later
4:25
Add one more item, say... Actually add a few more items
4:46
I'm going to add these few more items to the Obviously you can remove items using remove button
5:09
Okay, so as you can see, we added five items to the list view control here
5:39
one thing you may notice here is all these items are all in one row
5:44
but since it's just a string so I would rather have them listed in a list box
5:48
list box item so here's the main difference between list box and list view
5:53
a list view can be used to provide multiple views of the same data same item so if you look at the view property this is very
6:03
important property of list view that makes a control list view not a list box
6:08
So, as you can see by default, large icon property is set as a view
6:14
So if you look at click on this little icon you will see it has one two three four five it has five different views so it can be tile which entire you will see the view changes if
6:27
you go to list so as soon as I change my view to list as you can see all
6:33
items are displayed in a list in a list manner so actually I can even change the
6:40
size of column and do everything else I can select anything I want so I'm going
6:45
to discuss all these different views in my next video I don't want to make this video like a two hours video so so in
6:53
this so let's add a few more change few more properties and then we are almost
6:57
done with this so multi select is true already show groups is true scrollable
7:05
is true show tool tips I'll say true
7:16
Alright Can label Edit labels
7:28
Can change header style what kind of header you want a clickable header
7:32
None click no header at all Say yes Grid lines you can show grid lines true
7:38
This is important when you will have multiple columns and multiple rows
7:42
Full row select true so these are all general properties you will see one more thing you can do is
7:51
dark dog property if you say fill is going to fill in the whole form so let's
7:58
hit F5 which will build and run this sample what you will see is a list box
8:04
kind of looking list you control where you can select items and you can also see
8:08
tool tip if you notice so This is it for this part one of Listview tutorials
8:20
I'm going to discuss more functionalities and properties and methods available in Listview Control in my next videos