5 Replies - 14575 Views - Last Post: 01 March 2010 - 06:21 AM Rate Topic: -----

#1 buffdaemon_live  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-August 08

hiding first column in ListView

Posted 12 August 2008 - 01:55 PM

Is it possible to hide a listview control column? I want to have the first column hidden but with value held in it. I have Columns like StudentID, Student Name and StudentAddress and i am using StudentID as a primary key that is used to manipulate database. Below is my code. My code given below populates the list view. This function takes the SQL as query string and ListView as the name of the control.
Sub populateListView(ByVal sql As String, ByVal mylView As ListView)

'Clear Old items of ListView

mylView.Items.Clear()

mylView.Columns.Clear()

Try

Dim con As SqlConnection = dbConnect()

Dim sqlCmd As New SqlCommand(sql)

sqlCmd.Connection = con

con.Open()

sqlCmd.ExecuteNonQuery()

Dim dr As SqlDataReader = sqlCmd.ExecuteReader

Dim sCtr As Integer

'Read the columns from data reader and add to ListView

For sCtr = 0 To dr.FieldCount - 1

Dim lvwColumn As New ColumnHeader

lvwColumn.Text = dr.GetName(sCtr)

mylView.Columns.Add(lvwColumn)

Next

Do While dr.Read

Dim lvItem As New ListViewItem

lvItem.Text = dr(0)

For sCtr = 1 To dr.FieldCount - 1

If dr.IsDBNull(sCtr) Then

lvItem.SubItems.Add("")

Else

lvItem.SubItems.Add(dr.GetString(sCtr))

End If

Next sCtr

mylView.Items.Add(lvItem)

Loop

dr.Close()

sqlCmd.Dispose()

con.Close()

Catch ex As Exception

MsgBox(ex.ToString)

End Try

End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: hiding first column in ListView

#2 allensmith  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 11
  • Joined: 04-June 08

Re: hiding first column in ListView

Posted 12 August 2008 - 02:44 PM

Hello,

We do not have the option to hide or set visibility of a ListViewColumn to False.

However, we can either remove the column or probably try setting the width to 0.

Me.ListView1.Columns(1).Width = 0

I hope this will help.

Regards,

Allen
Was This Post Helpful? 0
  • +
  • -

#3 ranjithit23@gmail.com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-February 10

Re: hiding first column in ListView

Posted 01 March 2010 - 05:24 AM

View Postbuffdaemon_live, on 12 August 2008 - 12:55 PM, said:

Is it possible to hide a listview control column? I want to have the first column hidden but with value held in it. I have Columns like StudentID, Student Name and StudentAddress and i am using StudentID as a primary key that is used to manipulate database. Below is my code. My code given below populates the list view. This function takes the SQL as query string and ListView as the name of the control.
Sub populateListView(ByVal sql As String, ByVal mylView As ListView)

'Clear Old items of ListView

mylView.Items.Clear()

mylView.Columns.Clear()

Try

Dim con As SqlConnection = dbConnect()

Dim sqlCmd As New SqlCommand(sql)

sqlCmd.Connection = con

con.Open()

sqlCmd.ExecuteNonQuery()

Dim dr As SqlDataReader = sqlCmd.ExecuteReader

Dim sCtr As Integer

'Read the columns from data reader and add to ListView

For sCtr = 0 To dr.FieldCount - 1

Dim lvwColumn As New ColumnHeader

lvwColumn.Text = dr.GetName(sCtr)

mylView.Columns.Add(lvwColumn)

Next

Do While dr.Read

Dim lvItem As New ListViewItem

lvItem.Text = dr(0)

For sCtr = 1 To dr.FieldCount - 1

If dr.IsDBNull(sCtr) Then

lvItem.SubItems.Add("")

Else

lvItem.SubItems.Add(dr.GetString(sCtr))

End If

Next sCtr

mylView.Items.Add(lvItem)

Loop

dr.Close()

sqlCmd.Dispose()

con.Close()

Catch ex As Exception

MsgBox(ex.ToString)

End Try

End Sub


Thanks a Lot in Advance!!..

I have problem in hiddig a first value in list box is that possible to hide ......pls its very urgent.......!!!

Thanks a Lot in Advance!!..

I have problem in hiddig a first value in list box is that possible to hide ......pls its very urgent.......!!!
Was This Post Helpful? 0
  • +
  • -

#4 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: hiding first column in ListView

Posted 01 March 2010 - 05:33 AM

As said before, you cant hide it...


You can remove it though, but then ist gone..
Was This Post Helpful? 0
  • +
  • -

#5 ranjithit23@gmail.com  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-February 10

Re: hiding first column in ListView

Posted 01 March 2010 - 05:58 AM

ya,ofcoze some what help full!!!..........
Was This Post Helpful? 0
  • +
  • -

#6 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,196
  • Joined: 25-September 09

Re: hiding first column in ListView

Posted 01 March 2010 - 06:21 AM

You could also store the id in the listitem.tag


For sCtr = 0 To dr.FieldCount - 1

Dim lvwColumn As New ColumnHeader

lvwColumn.Text = dr.GetName(sCtr)
lvwColumn.Tag = 'Your recordID
mylView.Columns.Add(lvwColumn)

Next



Then when you need to use it based on the selecteditem in your listview you could use
myRecordID = lvwColumn.FocusedItem.Tag

This post has been edited by CharlieMay: 01 March 2010 - 06:57 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1