Formatting datagrids at run time

C

coleenholley

Hi all :-

I have a datagrid which is populated from a class module (we have to do this because of the type connection we use -we DON'T use an SQL Server connection) the code populates the datatable at runtime. I need to specify column widths in the data grid in order to get the look & Feel correct for our users. I create the data column headers using

dt_worksheet1.Columns.Add(New DataColumn("County")) ... in the VB code and populate using

ls_temp_arr = ls_temp.Substring(li_county_name, li_county_name_len).Trim(
ls_county = ls_temp_arr.ToString().Tri
dr_gallons(0) = ls_count

the problem is that some of the headers are longer and won't wrap correctly. I know that if I use bound datacolumns in the datagrid I can specify the column width, but because of the way we populate the datagrid, when I set the bound columns, the datagrid won't populate. Any way to do this programatically in the VB code behind? Thanks for any help/suggestions

Coleen
 
S

Scott Allen

Hi Coleen:

You can programtically add bound columns to a DataGrid (see below).
I'm assuming you are using ASP.NET since this is the ASP.NET
newsgroup, but I'm not aware of a single, simple property you can set
to control column width in the web forms datagrid.

BoundColumn c = new BoundColumn()
c.DataField = "DataField";
c.DataFormatString = ...
c.SortExpression = ...
....
DataGrid1.Columns.Add(c);

HTH,
 
C

coleenholley

Thanks for your help Scott :-

Yes, I'm using ASP.Net, with VB code-behind. I've got the columns all coming correctly using the VB Class module in the code-behind, but the column widhts are set to auto-generate at run-time. The problem with this is that in the datagrid properties, when I set it to auto-generate, the column widths do not generate how I want them to look. If I bind to the datacolumns, because of the way we connect to DB2 using an RPC from COBOL the data is not populated into the datagrid. I'm sure there has to be a way to do this...
 

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

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top