Hide/Rename Column in Datagrid

  • Thread starter Thread starter Billy
  • Start date Start date
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?
 
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
 
You can hide the id column by simply setting the type to hidden:

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

greets Gerben.
 
Back
Top