change the Column width of a Datagrid Populated through DataTable

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
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
 
Back
Top