change the Column width of a Datagrid Populated through DataTable

G

Guest

Hi,
I have datagrid.
I am populating the data in the datagrid from an xml file through an
DataTable.
Now i want to increase the width of the First column in my DataGrid.

Can some one tell me how i can do it.

Thanks in Advance,
Murthy
 
G

Guest

Hi,
I tried DataGridTableStyle but it is giving some errors.

Here is the code i tried.

// This will populate the Datagrid with a DataTable......
dGVoyageSummary.DataSource = XML.GetFileSummary();
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = "Employees";
dGVoyageSummary.TableStyles.Clear();
dGVoyageSummary.TableStyles.Add(ts);
// Assign New Width to DataGrid column
// The table contains a column with name Voyage that i want to resize.
dGVoyageSummary.TableStyles["Employees"].GridColumnStyles["Voyage"].Width =
12;

It is throughing me null reference exception.
what is missing in my code........

Thanks for ur reply.....
Murthy.
 
B

biondo

First create datagridtablestyle...
then define/add gridcolumn styles...
in the end add datagridtablestyle to the datagrid tablestyle collections...

So you have to define ALL the columns (datagridtextboxcolumns)
and add those columns to the datagridtablestyle (ts.gridcolumnstyle.add)

Because you haven't columns added you get the null exception

maurizio



Murthy said:
Hi,
I tried DataGridTableStyle but it is giving some errors.

Here is the code i tried.

// This will populate the Datagrid with a DataTable......
dGVoyageSummary.DataSource = XML.GetFileSummary();
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = "Employees";
dGVoyageSummary.TableStyles.Clear();
dGVoyageSummary.TableStyles.Add(ts);
// Assign New Width to DataGrid column
// The table contains a column with name Voyage that i want to resize.
dGVoyageSummary.TableStyles["Employees"].GridColumnStyles["Voyage"].Width
=
12;

It is throughing me null reference exception.
what is missing in my code........

Thanks for ur reply.....
Murthy.


biondo said:
Look for DataGridTableStyle...

maurizio
 

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