Hide/Rename Column in Datagrid

B

Billy

I want to use a XML document as the DataSource of a
DataGrid. I am doing this simply by:

DataSet dataset;
string xmlfilelocation = @"C:\source.xml";
dataset.ReadXml(xmlfilelocation);

There are two things I want to achieve:
1) Hide the "id" column of the dataset.
2) Change the physical column name to something more
meaningful to the users.

I've searching arround the internet for answer, somebody
suggest using the DataTableMapping/DataColumnMapping to
solve the problem.

However, the above methods are used with the DataAdapter,
in which it is not the way I get the data from.
As shown before, I just use the ReadXml method from
DataSet to read in the data.

So in my case, what can I do to achieve my two objectives?
 
K

Kris

DataGridTableStyles are used on the grid, here's a small example to get you
started :

DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = "Categorie";

DataGridTextBoxColumn colstyle = new DataGridTextBoxColumn();
colstyle.MappingName = "ca_name";
colstyle.HeaderText = "Name";
colstyle.Width = 300;
ts.GridColumnStyles.Add(colstyle);

if (!grdProducts.TableStyles.Contains(ts.MappingName))
{
grdProducts.TableStyles.Add(ts);
}


This shows only the 'ca_name' field and renames it to 'Name'


hope this helps

Kris
 
G

Gerben van Loon

You can hide the id column by simply setting the type to hidden:

Dataset.table.Columns["ID"].ColumnMapping = MappingType.Hidden;

greets Gerben.
 

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