hdding columns in a datagrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm writing an application for a pocket pc ( .net compact framework ).

I have a datatable (DTCustomers) with 12 columns which contains data about
customers.

I want to show this datatable in a datagrid, but only 3 columns of it.

How can I filter these columns out my datatable?

Regards
Frederik Duchi
 
This question gets asked so often in the .Net groups, that it must not be
very noticeable in any of the MS documentation (and I don't recall where I
first read it either, perhaps the Sceppa book). In any event, before you
assign the datasource, hide the columns you do not want to show:

ds.Tables("dtCustomers").Columns("ID").ColumnMapping = MappingType.Hidden

Datagrid1.datasource = ds.Tables("dtCustomers")
 
This solution isn't working for me.
I'm using this code
--------------------------------------------------------------------------------
Dim oDS As New DataSet

oDS.Tables.Add(Me.CustomersDatatable)

oDS.Tables(0).Columns("Code").ColumnMapping = MappingType.Hidden
oDS.Tables(0).Columns("street").ColumnMapping = MappingType.Hidden

dgCustomers.DataSource = oDS.Tables(0
---------------------------------------------------------------------------------

Me.CustomersDatatable is a property om my form. It is filled when I create
a new instance of the form

Regards
Frederik Duchi
 
Not sure what "isn't working". Is the datasource showing but the columns
aren't hidden? Or is the table not showing in the grid at all? Try
specifying the table name instead of ordinal position. Alternatively, check
what ordinal(0) contains. The results should be revealing.

MsgBox(oDS.Tables(0).TableName.ToString)
 
The datasource showed all the columns, but the problem is solved with using
the name of the datatable instead of his position.

Thanks
Frederik Duchi
 
Back
Top