473,387 Members | 1,779 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,387 software developers and data experts.

Multiple Columns in a ListView??

Hi,

I am trying to use a VB.NET listview object to display information
from a datatable. I need to have two columns of information but I
don't want the user to be able to select each column individually -
that's why I am attempting to use a listview rather than a datagrid.

I have been reading a lot of postings in this newsgroup concerning
multiple columns in listviews and I have tried to follow all the
advice I have found - but I am still having trouble. I have not been
able to get the second column of information to show up in the
listview.

Here is my code:

Dim tbl As DataTable = New DataTable
Dim col As Integer
Dim row As DataRow
Dim lvi As ListViewItem

tbl.Columns.Add("test")
tbl.Columns.Add("test2")

row = tbl.NewRow
row(0) = "help"
row(1) = "help me"
tbl.Rows.Add(row)

NodeList.BeginUpdate()
For col = 1 To tbl.Columns.Count
'Create a listview column for each dataset column
NodeList.Columns.Add(New ColumnHeader)
Next

row = Nothing
For Each row In tbl.Rows
'Create a listview item for each row in dataset, using text from
col0
lvi = New ListViewItem(CStr(row(0)))
col = 1
Do While col < tbl.Columns.Count - 1
'Append the subsequent columns
lvi.SubItems.Add(row(col))
col += 1
Loop
NodeList.Items.Add(lvi)
Next

Does anyone know what I am doing wrong??

Also, for some reason, I am having trouble with my Visual Studio 2003
program - it doesn't detect/recognize my code or any errors I make
until I compile it - this just started happening yesterday when I
started working with this problem - so I don't know if they are in any
way connected but I thought I would just mention it just in case.

Any advice would be greatly appreciated!!

Joy
Nov 21 '05 #1
3 4242
> Do While col < tbl.Columns.Count - 1
'Append the subsequent columns


I think you're actually missing the last column with the line of code
above..

change that line to either:
Do While col <= tbl.Columns.Count - 1

or

Do While col < tbl.Columns.Count
hope this helps..
Imran.
Nov 21 '05 #2

Sorry - that was a typo - you are right - but unfortunately that doesn't
resolve my problem - any other ideas??


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3
Option Strict On
Dim tbl As DataTable = New DataTable

Dim row As DataRow
tbl.Columns.Add("test")
tbl.Columns.Add("test2")

row = tbl.NewRow
row(0) = "help"
row(1) = "help me"
tbl.Rows.Add(row)

For col As Integer = 1 To tbl.Columns.Count
'Create a listview column for each dataset column
NodeList.Columns.Add(New ColumnHeader)
Next

NodeList.BeginUpdate() <-- moved this here, (don't think it will help with
add columns)
For Each row In tbl.Rows
'Create a listview item for each row in dataset, using text from col0()
Dim lvi As ListViewItem
lvi = New ListViewItem(row(0).ToString)
Dim col As Integer = 1
Do While col <= tbl.Columns.Count - 1
'Append the subsequent columns
lvi.SubItems.Add(row(col).ToString)
col += 1
Loop
NodeList.Items.Add(lvi)
Next
NodeList.EndUpdate() ' <-- this might be what your missing

HTH,
Greg

"Joy Labadie" <si***********@yahoo.com> wrote in message
news:eG**************@TK2MSFTNGP10.phx.gbl...

Sorry - that was a typo - you are right - but unfortunately that doesn't
resolve my problem - any other ideas??


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #4

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

Similar topics

4
by: Brandon Potter | last post by:
I think I'm going crazy, but I cannot remember how to create a listbox with multiple columns as well as the sortable header block (a la Outlook message list). I've seen the examples of how to...
3
by: Rob Richardson | last post by:
Greetings! I am attempting to display data in tabular form using a ListView control in detail mode. This is for a program I originally wrote in VB6. In VB6, I would add an item to the...
0
by: CR | last post by:
I'm having a problem with the Listview control. I populated a Listview with 4 columns. On my PC they show up just fine, the right hand edge of the 4th column lines up with the right hand edge of...
6
by: Maileen | last post by:
Hi, I have a listview in report mode. I have 3 columns in this listview and 1 column i would like to hide it from user's view. i tried to give width = 0 but user is still able to resize column...
5
by: John Devlon | last post by:
Hi, Does anyone know how to get a value of a second column of a selected item in Listview. I've create a listview and added this code Listview.Items.Clear() Listview.Columns.Clear()...
1
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Short of writing a custom version of the ListView control, is there a way to force the column headers to contain multiple lines. The problem is that the actual values of the items in each column...
2
by: ray well | last post by:
i need to display 2 columns of data in a list box. how would i set this up IN CODE. say my table is tblNames, and i have 2 fields, FirstName, LastName, and want the data to show up in 2...
3
by: John | last post by:
Hi Does listbox in vs2008 support multiple columns? I have not been able to set the column widths property to 10, 20, 30 for instance as it expects an int32 value. Thanks Regards
1
by: spowel4 | last post by:
Is it possible to have a listview with multiple columns but only the last column is checked? In other words none of the other columns would have checkboxes.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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
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...

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.