PDA

Click to See Complete Forum and Search --> : Hiding a column in a Windows Form Datagrid


mick lennon
Dec 21st, 2001, 03:44 AM
Hi Folks,
Ive created a master detail form using some text boxes and a datagrid bound to two tables related with a dataset relation.
I want to hide the datagrid column of the field I am relating on; palletid in the code below.

Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Dim cm As CurrencyManager

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Get the data.
Dim con As New SqlConnection("server=fred;uid=qpt_u;pwd=p_qpt;database=qpt")

Dim daPallet As New SqlDataAdapter("Select * from Palletdetails", con)
Dim daSerialno As New SqlDataAdapter("Select serialno, palletid from Serialno", con)

' I only want to show the serialno field in the grid

Dim ds As New DataSet()
daPallet.Fill(ds, "Palletdetails")
daSerialno.Fill(ds, "Serialno")
ds.Relations.Add("Pallet_Details", ds.Tables!Palletdetails.Columns!palletid, ds.Tables!Serialno.Columns!palletid)
'
'Bind the controls.
'
TextBox1.DataBindings.Add("Text", ds.Tables!Palletdetails, "palletid")
TextBox2.DataBindings.Add("Text", ds.Tables!Palletdetails, "tla")
TextBox3.DataBindings.Add("Text", ds.Tables!Palletdetails, "rev")
DataGrid1.DataSource = ds.Tables!Palletdetails
DataGrid1.DataMember = "Pallet_Details"


'
'Initialize the CurrencyManager.
'
cm = CType(Me.BindingContext(ds.Tables!Palletdetails), CurrencyManager)
End Sub

Cheers in Advance