|
-
Jun 8th, 2004, 01:25 AM
#1
Thread Starter
Lively Member
Hiding a column in Datagrid
Hi, I am using the following technique to hide a column in a datagrid. It works great, however, I am not able to get the item value anymore by calling
DataGrid1.Item(DataGrid1.CurrentRowIndex(), 0)
Is there a way to hide a column using this method and still get the value from the datagrid?
I do not want to use a Datagrid Table Style
VB Code:
Dim cn As New SqlConnection("Data Source=MyServer;User Id=MyUser;Password=MyPassword;Initial Catalog=Northwind")
cn.Open()
Dim da As New SqlDataAdapter("Select * From Products", cn)
Dim ds As New DataSet()
da.FillSchema(ds, SchemaType.Source, "Products")
da.Fill(ds, "Products")
' Next line hides column.
ds.Tables("Products").Columns("QuantityPerUnit").ColumnMapping = MappingType.Hidden
DataGrid1.SetDataBinding(ds, "Products")
Thanks in advance
Diego
Last edited by dterza01; Jun 8th, 2004 at 01:30 AM.
-
Jun 8th, 2004, 01:40 AM
#2
Member
You can also use your DataSet's ColumnMapping property to hide a column.
Imports System.Data.OleDb
'
' Retrieve "Customer" data from database.
'
Dim strConnection = "Provider=..."
Dim strSQL = "SELECT * FROM Customers"
Dim conn As New OleDbConnection(strConnection)
Dim DA As New OleDbDataAdapter(strSQL,conn)
Dim DS As New DataSet()
DA.Fill(DS, "Customers")
'
' Hide the column.
'
DS.Tables("Customers").Columns("LastName").ColumnMapping = MappingType.Hidden
DataGrid.DataSource = DS.Tables("Customers")
-
Jun 8th, 2004, 09:06 AM
#3
Thread Starter
Lively Member
Am I missing something? That is exactly what I did and explained above.
Please elaborate.
The problem is not how to hide the column but how to access the information from the hidden column on the datagrid
-
Jun 8th, 2004, 10:00 AM
#4
Frenzied Member
You could set the width to 0.
-
Jun 8th, 2004, 11:33 AM
#5
Thread Starter
Lively Member
Thank you but that will involve defining a DataGridTableStyle and that is exactly what I want to aviod (see code below).
Alternatively, I can get the value from the Dataset by using
DS.Tables("tblSQL").Rows(grdObs.CurrentRowIndex())("bObsNumber")
but if the user changes the sorting order on the datagrid this method does not work.
VB Code:
Dim aGridTableStyle As New DataGridTableStyle
aGridTableStyle.MappingName = "tblSQL"
Dim aCol1 As New DataGridTextBoxColumn
Dim aCol2 As New DataGridTextBoxColumn
Dim aCol3 As New DataGridTextBoxColumn
Dim aCol4 As New DataGridTextBoxColumn
Dim aCol5 As New DataGridTextBoxColumn
With aCol1
.MappingName = "bObsNumber"
.Width = 0
End With
With aCol2
.MappingName = "SupNumber"
.Width = 0
End With
With aCol3
.MappingName = "Invoice"
End With
With aCol4
.MappingName = "Date"
End With
With aCol5
.MappingName = "Time"
End With
With aGridTableStyle.GridColumnStyles
.Add(aCol3)
.Add(aCol4)
.Add(aCol5)
.Add(aCol1)
.Add(aCol2)
End With
'
' Add the GridColumnStyles to the aGridTableStyle.
'
grdObs.TableStyles.Add(aGridTableStyle)
-
Jun 10th, 2004, 10:53 PM
#6
Thread Starter
Lively Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|