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
hiding first column in ListView
Page 1 of 15 Replies - 11194 Views - Last Post: 01 March 2010 - 06:21 AM
#1
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.
Replies To: hiding first column in ListView
#2
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
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
#3
Re: hiding first column in ListView
Posted 01 March 2010 - 05:24 AM
buffdaemon_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.......!!!
#4
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..
You can remove it though, but then ist gone..
#5
Re: hiding first column in ListView
Posted 01 March 2010 - 05:58 AM
ya,ofcoze some what help full!!!..........
#6
Re: hiding first column in ListView
Posted 01 March 2010 - 06:21 AM
You could also store the id in the listitem.tag
Then when you need to use it based on the selecteditem in your listview you could use
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
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|