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 ListViewmylView.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 ColumnHeaderlvwColumn.Text = dr.GetName(sCtr)
mylView.Columns.Add(lvwColumn)
Next Do While dr.Read Dim lvItem As New ListViewItemlvItem.Text = dr(0)
For sCtr = 1 To dr.FieldCount - 1 If dr.IsDBNull(sCtr) ThenlvItem.SubItems.Add(
"") ElselvItem.SubItems.Add(dr.GetString(sCtr))
End If Next sCtrmylView.Items.Add(lvItem)
Loopdr.Close()
sqlCmd.Dispose()
con.Close()
Catch ex As ExceptionMsgBox(ex.ToString)
End Try End Sub
KarthikeyanPosted Jun 23, 2009, 4:22 PM
Niradhip ChakrabortyPosted Aug 12, 2008, 6:02 PM
You can hide a listview column by settings its Width property to 0 (zero.) Set myListView.Columns(0).Width = 0 and myListView.Columns(1).Width = -2 (auto-size) after you load your data.
You also can refer the following article.
http://www.codeproject.com/KB/list/listview.aspx
buff daemonPosted Aug 12, 2008, 5:11 PM
Niradhip ChakrabortyPosted Aug 12, 2008, 5:03 PM
Use inline coding to write condition into your .aspx page and u will be able to hide the column of Listview for particular criteria.
Try tis:
<%if (
<%} %>
above code will be hide the column3 & shows only 3 column (Column1, Column2, Column4)when if condition evolute true otherwise will be display all 4 columns.
You also can refer the following URL:
http://forums.msdn.microsoft.com/en-US/vblanguage/thread/b50a404a-ae4c-4cb2-92a0-db159aeba767/