3 Replies - 3447 Views - Last Post: 27 October 2009 - 06:57 AM Rate Topic: -----

Topic Sponsor:

#1 dlastral  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 20-October 09

ListView add value in 2 columns

Posted 27 October 2009 - 03:05 AM

I want to add t value in column1 and m value in column2 when I press a button.


My code adds the both values in first column.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		ListView1.Items.Add("t")
		ListView1.Items.Add("m")

	End Sub



Here is a printscreen:

Posted Image

So I want 1 value in column 1(Meciuri) and 1 value in column2 (Rezultat).

Is This A Good Question/Topic? 0
  • +

Replies To: ListView add value in 2 columns

#2 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 79
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: ListView add value in 2 columns

Posted 27 October 2009 - 03:35 AM

Each row in the listview is represented by a ListViewItem. Each ListViewItem has the main Item, which appears in the first column, and SubItems which appear in the other columns. So start with a fresh ListViewItem, add the main Item, then the SubItems, then add the whole ListViewItem to the ListView:

Dim lvi As New ListViewItem("t")
lvi.SubItems.Add("m")
ListView1.Items.Add(lvi)


I find it is usually neater to subclass ListViewItem and add a constructor to take and parse your data source into the Main item and SubItems.

This post has been edited by crepitus: 27 October 2009 - 03:36 AM

Was This Post Helpful? 1
  • +
  • -

#3 dlastral  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 20-October 09

Re: ListView add value in 2 columns

Posted 27 October 2009 - 04:23 AM

View Postcrepitus, on 27 Oct, 2009 - 02:35 AM, said:

Each row in the listview is represented by a ListViewItem. Each ListViewItem has the main Item, which appears in the first column, and SubItems which appear in the other columns. So start with a fresh ListViewItem, add the main Item, then the SubItems, then add the whole ListViewItem to the ListView:

Dim lvi As New ListViewItem("t")
lvi.SubItems.Add("m")
ListView1.Items.Add(lvi)


I find it is usually neater to subclass ListViewItem and add a constructor to take and parse your data source into the Main item and SubItems.


Thanks crepitus for your help and time to explain this!

I have another question how to use one line space between items?

Example:


Meciuri Rezultat

t m

here is a linespace

and then

t1 m1
Best wishes,

dlastral

This post has been edited by dlastral: 27 October 2009 - 04:34 AM

Was This Post Helpful? 0
  • +
  • -

#4 dlastral  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 20-October 09

Re: ListView add value in 2 columns

Posted 27 October 2009 - 06:57 AM

I discovered myself how to do:

  Dim spatiu1 As New ListViewItem
		spatiu1.SubItems.Add("")
		ListView1.Items.Add(spatiu1)





Thanks anyway!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1