Forms Newbie: How to stop DataGridView display default columns

  • Thread starter Thread starter DH
  • Start date Start date
D

DH

Hi All

How do I stop my DataGridView from displaying all the default columns from
my DataSet?

Thanks

DH
 
Well I don't know if this will help but in the code below I defined a
"table style" (after loading the datagrid) with just two columns - and that
is all the datagrid displays... Maybe there is an easier way to get what
you want though... I am quite new to .net

Brad

Private Sub frmAssetMaster_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim ds As New DataSet()

Dim dgTableStyle As DataGridTableStyle

SqlDataAdapter1.Fill(ds)

Me.DataGrid1.DataSource = ds

Me.DataGrid1.DataMember = "ComputerMaster"

'Create a data grid table style.

dgTableStyle = New DataGridTableStyle()

'Map the table style to a table

dgTableStyle.MappingName = "ComputerMaster"

' Declare two columns

Dim dgTextBoxCol As New DataGridTextBoxColumn()

Dim dgTextBoxCol2 As New DataGridTextBoxColumn()

' Set column 1 properties

dgTextBoxCol.MappingName = "ComputerName"

dgTextBoxCol.NullText = ""

dgTextBoxCol.HeaderText = "Asset Name"

' Set column 2 properties

dgTextBoxCol2.MappingName = "RAM"

dgTextBoxCol2.NullText = ""

dgTextBoxCol2.HeaderText = "RAM"

' Add the columns to the table style

dgTableStyle.GridColumnStyles.Add(dgTextBoxCol)

dgTableStyle.GridColumnStyles.Add(dgTextBoxCol2)

' Add the table style

Me.DataGrid1.TableStyles.Add(dgTableStyle)

endsub
 
How do I stop my DataGridView from displaying all the default columns from
my DataSet?

At runtime you can set AutoGenerateColumns = false, unfortunately MS did
not expose this property at designtime.
 
Back
Top