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

listview question

SA
My listview has 3 columns i.e. name, populaiton, and country code in order.
I use following code to insert data into listview and I find that I can't
assign which subitem related to related field. e.g. assign population to
column2. In vb 6, I can do it by "subitems(i). How about in .net? thx.

i = 0
While MyDataAdapter.Read
ListView1.Items.Add("")
ListView1.Items(i).Text = CStr(MyDataAdapter("name"))
ListView1.Items(i).SubItems.Add(MyDataAdapter("pop ulation"))
ListView1.Items(i).SubItems.Add(MyDataAdapter("Cou ntryCode"))
i = i + 1
End While
Nov 20 '05 #1
3 2265
Hi,

Dim strConn As String
Dim conn As SqlConnection
Dim drCustomer As SqlDataReader
Dim cmd As SqlCommand

strConn = "Server = " + Environment.MachineName + ";"
strConn += "Database = NorthWind;"
strConn += "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)
cmd = New SqlCommand("Select * from Customers", conn)
conn.Open()

Dim chID As New ColumnHeader
chID.Text = "Customer ID"
chID.Width = 70

Dim chCompany As New ColumnHeader
chCompany.Text = "Company Name"
chCompany.Width = 200

Dim chContact As New ColumnHeader
chContact.Text = "Contact Name"
chContact.Width = 150

ListView1.Columns.Add(chID)
ListView1.Columns.Add(chCompany)
ListView1.Columns.Add(chContact)

ListView1.View = View.Details

drCustomer = cmd.ExecuteReader
Do While drCustomer.Read
Dim lvi As New
ListViewItem(drCustomer.Item("CustomerID").ToStrin g)
lvi.SubItems.Add(drCustomer.Item("CompanyName").To String)
lvi.SubItems.Add(drCustomer.Item("ContactName").To String)
ListView1.Items.Add(lvi)
Loop
conn.Close()

Ken
--------------------
"SA" <te**@test.com> wrote in message
news:ek**************@TK2MSFTNGP12.phx.gbl...
My listview has 3 columns i.e. name, populaiton, and country code in
order.
I use following code to insert data into listview and I find that I can't
assign which subitem related to related field. e.g. assign population to
column2. In vb 6, I can do it by "subitems(i). How about in .net? thx.

i = 0
While MyDataAdapter.Read
ListView1.Items.Add("")
ListView1.Items(i).Text = CStr(MyDataAdapter("name"))
ListView1.Items(i).SubItems.Add(MyDataAdapter("pop ulation"))
ListView1.Items(i).SubItems.Add(MyDataAdapter("Cou ntryCode"))
i = i + 1
End While

Nov 20 '05 #2
SA
Firstly, thx but the order must be same in your code.
example, the column order is CustId, CompanyName, and Contact
During add record, I set a wrong order and the result is that contact name
data is added to column 2 i.e. Company Name.

ListViewItem(drCustomer.Item("CustomerID").ToStrin g)
lvi.SubItems.Add(drCustomer.Item("ContactName").To String)
lvi.SubItems.Add(drCustomer.Item("CompanyName").To String)
ListView1.Items.Add(lvi)

Is any mistake in my view? thx.

"Ken Tucker [MVP]" <vb***@bellsouth.net> ¼¶¼g©ó¶l¥ó·s»D
:#C**************@tk2msftngp13.phx.gbl...
Hi,

Dim strConn As String
Dim conn As SqlConnection
Dim drCustomer As SqlDataReader
Dim cmd As SqlCommand

strConn = "Server = " + Environment.MachineName + ";"
strConn += "Database = NorthWind;"
strConn += "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)
cmd = New SqlCommand("Select * from Customers", conn)
conn.Open()

Dim chID As New ColumnHeader
chID.Text = "Customer ID"
chID.Width = 70

Dim chCompany As New ColumnHeader
chCompany.Text = "Company Name"
chCompany.Width = 200

Dim chContact As New ColumnHeader
chContact.Text = "Contact Name"
chContact.Width = 150

ListView1.Columns.Add(chID)
ListView1.Columns.Add(chCompany)
ListView1.Columns.Add(chContact)

ListView1.View = View.Details

drCustomer = cmd.ExecuteReader
Do While drCustomer.Read
Dim lvi As New
ListViewItem(drCustomer.Item("CustomerID").ToStrin g)
lvi.SubItems.Add(drCustomer.Item("CompanyName").To String)
lvi.SubItems.Add(drCustomer.Item("ContactName").To String)
ListView1.Items.Add(lvi)
Loop
conn.Close()

Ken
--------------------
"SA" <te**@test.com> wrote in message
news:ek**************@TK2MSFTNGP12.phx.gbl...
My listview has 3 columns i.e. name, populaiton, and country code in
order.
I use following code to insert data into listview and I find that I can't assign which subitem related to related field. e.g. assign population to
column2. In vb 6, I can do it by "subitems(i). How about in .net? thx.

i = 0
While MyDataAdapter.Read
ListView1.Items.Add("")
ListView1.Items(i).Text = CStr(MyDataAdapter("name"))
ListView1.Items(i).SubItems.Add(MyDataAdapter("pop ulation"))
ListView1.Items(i).SubItems.Add(MyDataAdapter("Cou ntryCode"))
i = i + 1
End While


Nov 20 '05 #3
Hi,

Yes you are right

Ken
-----------
"SA" <te**@test.com> wrote in message
news:uS*************@TK2MSFTNGP09.phx.gbl...
Firstly, thx but the order must be same in your code.
example, the column order is CustId, CompanyName, and Contact
During add record, I set a wrong order and the result is that contact name
data is added to column 2 i.e. Company Name.

ListViewItem(drCustomer.Item("CustomerID").ToStrin g)
lvi.SubItems.Add(drCustomer.Item("ContactName").To String)
lvi.SubItems.Add(drCustomer.Item("CompanyName").To String)
ListView1.Items.Add(lvi)

Is any mistake in my view? thx.

"Ken Tucker [MVP]" <vb***@bellsouth.net> ¼¶¼g©ó¶l¥ó·s»D
:#C**************@tk2msftngp13.phx.gbl...
Hi,

Dim strConn As String
Dim conn As SqlConnection
Dim drCustomer As SqlDataReader
Dim cmd As SqlCommand

strConn = "Server = " + Environment.MachineName + ";"
strConn += "Database = NorthWind;"
strConn += "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)
cmd = New SqlCommand("Select * from Customers", conn)
conn.Open()

Dim chID As New ColumnHeader
chID.Text = "Customer ID"
chID.Width = 70

Dim chCompany As New ColumnHeader
chCompany.Text = "Company Name"
chCompany.Width = 200

Dim chContact As New ColumnHeader
chContact.Text = "Contact Name"
chContact.Width = 150

ListView1.Columns.Add(chID)
ListView1.Columns.Add(chCompany)
ListView1.Columns.Add(chContact)

ListView1.View = View.Details

drCustomer = cmd.ExecuteReader
Do While drCustomer.Read
Dim lvi As New
ListViewItem(drCustomer.Item("CustomerID").ToStrin g)
lvi.SubItems.Add(drCustomer.Item("CompanyName").To String)
lvi.SubItems.Add(drCustomer.Item("ContactName").To String)
ListView1.Items.Add(lvi)
Loop
conn.Close()

Ken
--------------------
"SA" <te**@test.com> wrote in message
news:ek**************@TK2MSFTNGP12.phx.gbl...
> My listview has 3 columns i.e. name, populaiton, and country code in
> order.
> I use following code to insert data into listview and I find that I can't > assign which subitem related to related field. e.g. assign population
> to
> column2. In vb 6, I can do it by "subitems(i). How about in .net? thx.
>
> i = 0
> While MyDataAdapter.Read
> ListView1.Items.Add("")
> ListView1.Items(i).Text = CStr(MyDataAdapter("name"))
> ListView1.Items(i).SubItems.Add(MyDataAdapter("pop ulation"))
>
> ListView1.Items(i).SubItems.Add(MyDataAdapter("Cou ntryCode"))
> i = i + 1
> End While
>
>



Nov 20 '05 #4

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

Similar topics

3
by: andrewcw | last post by:
I have a simple winform with the following code. But although I can read back the info, the display fails to provide the text or the cell background color changes. private void ListViewBroke()...
1
by: J_Max | last post by:
Hello, This might be a really easy question, but... I am developing a simple Smart Device application that uses a listview. I have a function that adds a item to the listview - code is below. I...
7
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...
3
by: MikeY | last post by:
Hopefully someone can help me on this. I am using C#, making Windows forms. I have created a listView with checkbox's. I have enabled the checkboxes under the properties, and all the data,...
1
by: Derck | last post by:
SORRY, for the crosspost, but I think I posted it in the wrong group! Hello all, I have a question.. I am tying to make a global listview class where other listviews in my application points...
12
by: J L | last post by:
When I fill a listview, I resize the columns to fit the data. I need to know if the data will fit vertically or if there will be a vertical scroll bar. I need to know this so I can allow for it on...
1
by: Chris | last post by:
Hi all, I posted the following in microsoft.public.dotnet.framework.windowsforms but it seems that group has little traffic. Hi all, I have a listview box which is populated from methods of...
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. ...
1
by: =?Utf-8?B?THluYkBtcy5jb20=?= | last post by:
I have a executable winforms application I would like to change. I use quite a number of listview controls in my main form. I dump about 15 columns of data into a couple of listviews. This data...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.