hdding columns in a datagrid

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
 
E

Earl

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")
 
G

Guest

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
 
E

Earl

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)
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top