By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

ListView Control

P: n/a
I have a form which has a ListView control named ListView1 added at design
time. When I add items using the following code, they don't appear in the
list view. However, if I create a ListView control in code and add it to the
form, it works. Why don't the items show up in the ListView that I added at
desgn time.

' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

' Create columns for the items and subitems.
ListView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3})

--
Dennis in Houston
Nov 21 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Thanks. I feel like an idiot. I have no idea why I had the -2 in the .Add
method.

I was mainly following the example for the ListView control in the MSDN as
follows:

listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

Do you have any idea why Microsoft put a -2 in for the Column Width? It
seemed to work ok if I created the control in code rather than at Design Time.

"Q" wrote:
Hello Dennis,

try to change the column width to a positive figur (eg 100)
If you do this, the columns will be visible.

Don't know why but I tried it and it works!

Regards,

Q
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
I have a form which has a ListView control named ListView1 added at design
time. When I add items using the following code, they don't appear in the
list view. However, if I create a ListView control in code and add it to

the
form, it works. Why don't the items show up in the ListView that I added

at
desgn time.

' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

' Create columns for the items and subitems.
ListView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3})

--
Dennis in Houston


Nov 21 '05 #2

P: n/a
I added a ListView1 at design and added your code, seemed to work fine.

I also added...

ListView1.View = View.Details
ListView1.CheckBoxes = True

Greg
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
I have a form which has a ListView control named ListView1 added at design
time. When I add items using the following code, they don't appear in the
list view. However, if I create a ListView control in code and add it to
the
form, it works. Why don't the items show up in the ListView that I added
at
desgn time.

' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

' Create columns for the items and subitems.
ListView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3})

--
Dennis in Houston

Nov 21 '05 #3

P: n/a
Does this help?

http://tinyurl.com/3z7ev

Greg

"Q" <Q@nomail.be> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello Dennis,

try to change the column width to a positive figur (eg 100)
If you do this, the columns will be visible.

Don't know why but I tried it and it works!

Regards,

Q
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
I have a form which has a ListView control named ListView1 added at
design
time. When I add items using the following code, they don't appear in
the
list view. However, if I create a ListView control in code and add it to

the
form, it works. Why don't the items show up in the ListView that I added

at
desgn time.

' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

' Create columns for the items and subitems.
ListView1.Columns.Add("Item Column", -2,
HorizontalAlignment.Left)
ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2,
item3})

--
Dennis in Houston


Nov 21 '05 #4

P: n/a
Q
Hello Dennis,

try to change the column width to a positive figur (eg 100)
If you do this, the columns will be visible.

Don't know why but I tried it and it works!

Regards,

Q
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
I have a form which has a ListView control named ListView1 added at design
time. When I add items using the following code, they don't appear in the
list view. However, if I create a ListView control in code and add it to the form, it works. Why don't the items show up in the ListView that I added at desgn time.

' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

' Create columns for the items and subitems.
ListView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3})

--
Dennis in Houston

Nov 21 '05 #5

P: n/a
Thanks. I feel like an idiot. I have no idea why I had the -2 in the .Add
method.

I was mainly following the example for the ListView control in the MSDN as
follows:

listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

Do you have any idea why Microsoft put a -2 in for the Column Width? It
seemed to work ok if I created the control in code rather than at Design Time.

"Q" wrote:
Hello Dennis,

try to change the column width to a positive figur (eg 100)
If you do this, the columns will be visible.

Don't know why but I tried it and it works!

Regards,

Q
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
I have a form which has a ListView control named ListView1 added at design
time. When I add items using the following code, they don't appear in the
list view. However, if I create a ListView control in code and add it to

the
form, it works. Why don't the items show up in the ListView that I added

at
desgn time.

' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

' Create columns for the items and subitems.
ListView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3})

--
Dennis in Houston


Nov 21 '05 #6

P: n/a
Does this help?

http://tinyurl.com/3z7ev

Greg

"Q" <Q@nomail.be> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello Dennis,

try to change the column width to a positive figur (eg 100)
If you do this, the columns will be visible.

Don't know why but I tried it and it works!

Regards,

Q
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
I have a form which has a ListView control named ListView1 added at
design
time. When I add items using the following code, they don't appear in
the
list view. However, if I create a ListView control in code and add it to

the
form, it works. Why don't the items show up in the ListView that I added

at
desgn time.

' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

' Create columns for the items and subitems.
ListView1.Columns.Add("Item Column", -2,
HorizontalAlignment.Left)
ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2,
item3})

--
Dennis in Houston


Nov 21 '05 #7

P: n/a
Q
Hey Dennis,

it seems that the values -1 and -2 can be used.
-1 : autosize to the largest subitem
-2 : autosize to the size of the text of the column header

I have tried both -1 and -2 and they only seem to be working with a listview
created during runtime.
If you use a listview that has been created at design time, these two
settings do not seem to work.

I have no idea why they don't work!

Regards,

Q

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
Thanks. I feel like an idiot. I have no idea why I had the -2 in the ..Add method.

I was mainly following the example for the ListView control in the MSDN as
follows:

listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

Do you have any idea why Microsoft put a -2 in for the Column Width? It
seemed to work ok if I created the control in code rather than at Design Time.
"Q" wrote:
Hello Dennis,

try to change the column width to a positive figur (eg 100)
If you do this, the columns will be visible.

Don't know why but I tried it and it works!

Regards,

Q
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
I have a form which has a ListView control named ListView1 added at design time. When I add items using the following code, they don't appear in the list view. However, if I create a ListView control in code and add it to
the
form, it works. Why don't the items show up in the ListView that I
added at
desgn time.

' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

' Create columns for the items and subitems.
ListView1.Columns.Add("Item Column", -2,

HorizontalAlignment.Left) ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left) ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left) ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)
'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3})
--
Dennis in Houston


Nov 21 '05 #8

P: n/a
Q
Hey Dennis,

it seems that the values -1 and -2 can be used.
-1 : autosize to the largest subitem
-2 : autosize to the size of the text of the column header

I have tried both -1 and -2 and they only seem to be working with a listview
created during runtime.
If you use a listview that has been created at design time, these two
settings do not seem to work.

I have no idea why they don't work!

Regards,

Q

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
Thanks. I feel like an idiot. I have no idea why I had the -2 in the ..Add method.

I was mainly following the example for the ListView control in the MSDN as
follows:

listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

Do you have any idea why Microsoft put a -2 in for the Column Width? It
seemed to work ok if I created the control in code rather than at Design Time.
"Q" wrote:
Hello Dennis,

try to change the column width to a positive figur (eg 100)
If you do this, the columns will be visible.

Don't know why but I tried it and it works!

Regards,

Q
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
I have a form which has a ListView control named ListView1 added at design time. When I add items using the following code, they don't appear in the list view. However, if I create a ListView control in code and add it to
the
form, it works. Why don't the items show up in the ListView that I
added at
desgn time.

' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

' Create columns for the items and subitems.
ListView1.Columns.Add("Item Column", -2,

HorizontalAlignment.Left) ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left) ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left) ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)
'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3})
--
Dennis in Houston


Nov 21 '05 #9

P: n/a
It would appear that when you set the column width in design mode there are
no items added yet (must be the order they are added in
InitializeComponent), so the autosize doesn't know what to do.

Try setting up the columns in design mode, but add the items in code. Then
reset the column width to -1 or -2. Seems to work for me.

Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3})

For Each col As ColumnHeader In ListView1.Columns
col.Width = -1
Next col

Greg

"Q" <Q@nomail.be> wrote in message
news:u9*************@TK2MSFTNGP12.phx.gbl...
Hey Dennis,

it seems that the values -1 and -2 can be used.
-1 : autosize to the largest subitem
-2 : autosize to the size of the text of the column header

I have tried both -1 and -2 and they only seem to be working with a
listview
created during runtime.
If you use a listview that has been created at design time, these two
settings do not seem to work.

I have no idea why they don't work!

Regards,

Q

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
Thanks. I feel like an idiot. I have no idea why I had the -2 in the

.Add
method.

I was mainly following the example for the ListView control in the MSDN
as
follows:

listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

Do you have any idea why Microsoft put a -2 in for the Column Width? It
seemed to work ok if I created the control in code rather than at Design

Time.

"Q" wrote:
> Hello Dennis,
>
> try to change the column width to a positive figur (eg 100)
> If you do this, the columns will be visible.
>
> Don't know why but I tried it and it works!
>
> Regards,
>
> Q
> "Dennis" <De****@discussions.microsoft.com> wrote in message
> news:F9**********************************@microsof t.com...
> > I have a form which has a ListView control named ListView1 added at design > > time. When I add items using the following code, they don't appear
> > in the > > list view. However, if I create a ListView control in code and add
> > it to > the
> > form, it works. Why don't the items show up in the ListView that I added > at
> > desgn time.
> >
> > ' Create three items and three sets of subitems for each item.
> > Dim item1 As New ListViewItem("item1", 0)
> > ' Place a check mark next to the item.
> > item1.Checked = True
> > item1.SubItems.Add("1")
> > item1.SubItems.Add("2")
> > item1.SubItems.Add("3")
> > Dim item2 As New ListViewItem("item2", 1)
> > item2.SubItems.Add("4")
> > item2.SubItems.Add("5")
> > item2.SubItems.Add("6")
> > Dim item3 As New ListViewItem("item3", 0)
> > ' Place a check mark next to the item.
> > item3.Checked = True
> > item3.SubItems.Add("7")
> > item3.SubItems.Add("8")
> > item3.SubItems.Add("9")
> >
> > ' Create columns for the items and subitems.
> > ListView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left) > > ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left) > > ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left) > > ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center) > >
> > 'Add the items to the ListView.
> > ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3}) > >
> > --
> > Dennis in Houston
>
>
>


Nov 21 '05 #10

P: n/a
It would appear that when you set the column width in design mode there are
no items added yet (must be the order they are added in
InitializeComponent), so the autosize doesn't know what to do.

Try setting up the columns in design mode, but add the items in code. Then
reset the column width to -1 or -2. Seems to work for me.

Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3})

For Each col As ColumnHeader In ListView1.Columns
col.Width = -1
Next col

Greg

"Q" <Q@nomail.be> wrote in message
news:u9*************@TK2MSFTNGP12.phx.gbl...
Hey Dennis,

it seems that the values -1 and -2 can be used.
-1 : autosize to the largest subitem
-2 : autosize to the size of the text of the column header

I have tried both -1 and -2 and they only seem to be working with a
listview
created during runtime.
If you use a listview that has been created at design time, these two
settings do not seem to work.

I have no idea why they don't work!

Regards,

Q

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
Thanks. I feel like an idiot. I have no idea why I had the -2 in the

.Add
method.

I was mainly following the example for the ListView control in the MSDN
as
follows:

listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

Do you have any idea why Microsoft put a -2 in for the Column Width? It
seemed to work ok if I created the control in code rather than at Design

Time.

"Q" wrote:
> Hello Dennis,
>
> try to change the column width to a positive figur (eg 100)
> If you do this, the columns will be visible.
>
> Don't know why but I tried it and it works!
>
> Regards,
>
> Q
> "Dennis" <De****@discussions.microsoft.com> wrote in message
> news:F9**********************************@microsof t.com...
> > I have a form which has a ListView control named ListView1 added at design > > time. When I add items using the following code, they don't appear
> > in the > > list view. However, if I create a ListView control in code and add
> > it to > the
> > form, it works. Why don't the items show up in the ListView that I added > at
> > desgn time.
> >
> > ' Create three items and three sets of subitems for each item.
> > Dim item1 As New ListViewItem("item1", 0)
> > ' Place a check mark next to the item.
> > item1.Checked = True
> > item1.SubItems.Add("1")
> > item1.SubItems.Add("2")
> > item1.SubItems.Add("3")
> > Dim item2 As New ListViewItem("item2", 1)
> > item2.SubItems.Add("4")
> > item2.SubItems.Add("5")
> > item2.SubItems.Add("6")
> > Dim item3 As New ListViewItem("item3", 0)
> > ' Place a check mark next to the item.
> > item3.Checked = True
> > item3.SubItems.Add("7")
> > item3.SubItems.Add("8")
> > item3.SubItems.Add("9")
> >
> > ' Create columns for the items and subitems.
> > ListView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left) > > ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left) > > ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left) > > ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center) > >
> > 'Add the items to the ListView.
> > ListView1.Items.AddRange(New ListViewItem() {item1, item2, item3}) > >
> > --
> > Dennis in Houston
>
>
>


Nov 21 '05 #11

P: n/a
Thanks to both you an Q for helping. I ddin't read in the documentation
about the -1 and -2 but it seems really strange that Microsoft would do this
instead of adding a properties like autosizeColumnHeaders, etc.

"Greg Burns" wrote:
Does this help?

http://tinyurl.com/3z7ev

Greg

"Q" <Q@nomail.be> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello Dennis,

try to change the column width to a positive figur (eg 100)
If you do this, the columns will be visible.

Don't know why but I tried it and it works!

Regards,

Q
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
I have a form which has a ListView control named ListView1 added at
design
time. When I add items using the following code, they don't appear in
the
list view. However, if I create a ListView control in code and add it to

the
form, it works. Why don't the items show up in the ListView that I added

at
desgn time.

' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

' Create columns for the items and subitems.
ListView1.Columns.Add("Item Column", -2,
HorizontalAlignment.Left)
ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2,
item3})

--
Dennis in Houston



Nov 21 '05 #12

P: n/a
Thanks to both you an Q for helping. I ddin't read in the documentation
about the -1 and -2 but it seems really strange that Microsoft would do this
instead of adding a properties like autosizeColumnHeaders, etc.

"Greg Burns" wrote:
Does this help?

http://tinyurl.com/3z7ev

Greg

"Q" <Q@nomail.be> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello Dennis,

try to change the column width to a positive figur (eg 100)
If you do this, the columns will be visible.

Don't know why but I tried it and it works!

Regards,

Q
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com...
I have a form which has a ListView control named ListView1 added at
design
time. When I add items using the following code, they don't appear in
the
list view. However, if I create a ListView control in code and add it to

the
form, it works. Why don't the items show up in the ListView that I added

at
desgn time.

' Create three items and three sets of subitems for each item.
Dim item1 As New ListViewItem("item1", 0)
' Place a check mark next to the item.
item1.Checked = True
item1.SubItems.Add("1")
item1.SubItems.Add("2")
item1.SubItems.Add("3")
Dim item2 As New ListViewItem("item2", 1)
item2.SubItems.Add("4")
item2.SubItems.Add("5")
item2.SubItems.Add("6")
Dim item3 As New ListViewItem("item3", 0)
' Place a check mark next to the item.
item3.Checked = True
item3.SubItems.Add("7")
item3.SubItems.Add("8")
item3.SubItems.Add("9")

' Create columns for the items and subitems.
ListView1.Columns.Add("Item Column", -2,
HorizontalAlignment.Left)
ListView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
ListView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

'Add the items to the ListView.
ListView1.Items.AddRange(New ListViewItem() {item1, item2,
item3})

--
Dennis in Houston



Nov 21 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.