473,320 Members | 2,052 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,320 software developers and data experts.

ListView Control

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
12 3065
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
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Welie | last post by:
Hi all- I am using a listview (MSComctlLib.ListViewCtrl.2)on an Access form. Actually there are six listviews on the form. I need to do the same thing to all six forms so I have the loop below....
2
by: Ken | last post by:
Hi all, Please help! I'm attempting to apply tooltips to each individual item in VB.Net's Listview control. In VB6 it was easy - you just did the following (assumes "myListView" is the name of...
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...
4
by: Pucca | last post by:
How can I tell a mouse right clicks over a listview item that's in a container panel. I only want to display a popup menu if the user right click the mouse over an item on the Listview. I don't...
3
by: Michael.Suarez | last post by:
Is it me, or does it seem like they put no effort into creating the listview control in .Net. listview. A few gripes I have with .Net listview that aren't present in vb6: -Inability to set...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
10
by: Rob | last post by:
VS 2005 How can you tell if a value is contained in a specific column (let's say column 1 named Status) of a ListView ? In a list box you could go... If ListBox1.Items.Contains(strWhatever)...
5
by: Mark Olbert | last post by:
How do I get the DataPager and ListView to play nice together when I use a custom datasource? In my webpage, I use linq to pull data from a SqlServer database and assign the resulting...
0
by: =?Utf-8?B?SWdvcg==?= | last post by:
Hi everyone! I have some strange behavior of ListView control in WPF. We are developing application in C#. I created ListView with some items and set SelectedIndex to some index in the...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.