Setting column width to datagrid doesn't work

E

ejsanchez

I'm using the following code to resize the column width of
my datagrid in the "Form_Load" method:

myDataGrid.TableStyles.Clear();
DataGridTableStyle dg1TabStyle=new DataGridTableStyle();
dg1TabStyle.MappingName="<table_name>";

DataGridTextBoxColumn col1=new DataGridTextBoxColumn();
col1.TextBox.Enabled=false;
col1.Alignment=HorizontalAlignment.Right;
col1.HeaderText="<Some Text>";
col1.MappingName="<table_col_name>";
col1.With=500;
dgTabStyle=GridColumnStyles.Add(col1);

myDataGrid.TableStyles.Add(sociosTableStyle);

This don't work :(
The columns in the Datagrid remain the same size, no change at all.
Any help or advice would be appreciated.
thanks in advance,

-eduardo s.m.
 
B

Bart Mermuys

Hi,

I'm using the following code to resize the column width of
my datagrid in the "Form_Load" method:

myDataGrid.TableStyles.Clear();
DataGridTableStyle dg1TabStyle=new DataGridTableStyle();
dg1TabStyle.MappingName="<table_name>";

DataGridTextBoxColumn col1=new DataGridTextBoxColumn();
col1.TextBox.Enabled=false;
col1.Alignment=HorizontalAlignment.Right;
col1.HeaderText="<Some Text>";
col1.MappingName="<table_col_name>";
col1.With=500;
dgTabStyle=GridColumnStyles.Add(col1);

myDataGrid.TableStyles.Add(sociosTableStyle);

This don't work :(
The columns in the Datagrid remain the same size, no change at all.
Any help or advice would be appreciated.
thanks in advance,

If the other properties don't work either ( HeaderText, Alignment ) then
most likely the MappingName of the DataGridTableStyle is wrong, verify it by
checking the TableName property of the relevant table.

HTH,
Greetings
 
E

ejsanchez

verify it by
checking the TableName property of the relevant table.

Thanks!, you were absolutely right, I was doing wrong the
mapping, setting the tablename solve my problems.

regards,
-eduardo s.m.
 

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