DataGrid Columns

D

David McCallum

I have a class (MyClass) with a number of public properties, say prop1,
prop2, prop3.....

My DataGrid's data source is a List<MyClass>

The problem is the grid shows all the properties, how do I restrict it ti
show only say prop2 and prop10

TIA

David McCallum
 
D

drozd

Arun,

Thanks for that, but I already tried that from an example I found. Can you have a look at my code and see if you see anything wrong. The two properties I want to display are FullIC and IcDescription, but as can be seen my the image all the columsn still show.

TIA

David

public ICSelector(List<IC> ics)

{

InitializeComponent();

ICGrid.DataSource = ics;

this.ics = ics;

// Creates two DataGridTableStyle objects, one for the Machine

// array, and one for the Parts ArrayList.

DataGridTableStyle ICTable = new DataGridTableStyle {MappingName = "List<IC>"};

// Sets the MappingName to the class name plus brackets.

// Creates three column styles.

var colFullIC = new DataGridTextBoxColumn();

// Property ic.FullIC

colFullIC.MappingName = "FullIC";

colFullIC.HeaderText = "IC";

DataGridTextBoxColumn colDescription = new DataGridTextBoxColumn();

// Property ic.IcDescription

colDescription.MappingName = "IcDescription";

colDescription.HeaderText = "Description";

// Adds the column styles to the grid table style.

ICTable.GridColumnStyles.Add(colFullIC);

ICTable.GridColumnStyles.Add(colDescription);

// Add the table style to the collection, but clear the

// collection first.

ICGrid.TableStyles.Clear();

ICGrid.TableStyles.Add(ICTable);

}



 ICSelector.jpg
38KViewDownload

Try setting ICTable.MappingName to the name of the element type, i.e.

DataGridTableStyle ICTable = new DataGridTableStyle {MappingName =
"IC"};

Hope that helps,
Micha³
 
A

Arun

Try this
DataGridTableStyle ICTable = new DataGridTableStyle();
ICTable.MappingName = ICGrid.DataSource.GetType().Name;

Try this too,
//Do clear default table style before applying customized
ICGrid.TableStyles.Clear();
ICGrid.TableStyles.Add(ICTable);

Hope this helps,
Cheers,
Arun
 
D

David McCallum

Arun,

Thanks that did it, finny thing is I expected
ICGrid.DataSource.GetType().Name to return List, List<T>, List<IC> or
something like that. Instead it returns List`1

Any ideas?

David





Try this
DataGridTableStyle ICTable = new DataGridTableStyle();
ICTable.MappingName = ICGrid.DataSource.GetType().Name;

Try this too,
//Do clear default table style before applying customized
ICGrid.TableStyles.Clear();
ICGrid.TableStyles.Add(ICTable);

Hope this helps,
Cheers,
Arun
 

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