Changing width of DataGrid component

  • Thread starter Thread starter glenn
  • Start date Start date
G

glenn

Can anyone tell me the easiest way to change the width of the colomns of a
datagrid. All the help files are telling me to set the PreferredColomnWidth
property but it does not seem to exist when I access the components
properties.

Can anyone tell me what I"m doing wrong that is making all the tutorials
provided with VS useless?

I'm using C#...

Thanks,

glenn
 
I hope you are kidding., I have a grid with 20 fields in it and I have to
set the colomn width like this for each field? Is there no other way? This
is insane... :-) sorry, but 10 lines of code to set one fields width and
header is just insane to me...

Can you please confirm that there is no other way to accomplish this? Is
there another component out there that actually has been designed to work
that I can purchase? I don't mind buying something if it works.

thanks

glenn
 
Actually only 5 :) ... and this sequence you may include into the
function and call as one line:


DataGridTableStyle dgts = new DataGridTableStyle();
void AddTBColumn(string fieldName, string header, int width)
{
DataGridColumnStyle c = new DataGridTextBoxColumn();
c.MappingName = fieldName;
c.HeaderText = header;
c.Width = width;
dgts.GridColumnStyles.Add(c);
}

....
dgts.MappingName = "TableName";

AddTBColumn("Field1", "Header1", 100);
AddTBColumn("Field2", "Header2", 100);
....
dataGrid1.TableStyles.Add(dgts);

Also you may consider SourceGrid:
http://www.devage.com/SourceGrid/SourceGrid2_EN.html

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
Thanks, that is what I did as I couldn't find another way to handle it.
However, I'm having problems with getting the grid to show all my columns.
It goes across to 6 columns wide and then just stops. No errors or
anything. Is there a limit on how many fields you can add? Or on the
length of any one field?

Thanks,

glenn
 
Back
Top