Datagrids???

  • Thread starter Thread starter Darryn Ross
  • Start date Start date
D

Darryn Ross

Hi,

When i popualte my datagrid the columns are all squashed together and not applying their set width.. my code is as follows..

first i do this..

DataGridTableStyle TSCA = new DataGridTableStyle() ;
TSCA.MappingName = "tbl" ;

DataGridColumnStyle TCCode = new DataGridTextBoxColumn() ;
TCCode.MappingName = "Code" ;
TCCode.HeaderText = "Code" ;
TCCode.Width = 11 ;
TSCA.GridColumnStyles.Add(TCCode) ;

dgCA.TableStyles.Add(TSCA) ;

then i do this...

CConnection.ConnectionString = StrConnectionPath ;
CConnection.Open() ;

SelectLstCommand.CommandText = "Select * From tbl" ;
SelectLstCommand.Connection = CConnection ;
CAdapter.SelectCommand = SelectLstCommand ;
CAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey ;
CAdapter.Fill(CDs, "tbl") ;
dgCA.SetDataBinding(CDs, "tbl") ;
CConnection.Close() ;

Any help would be appreciated.

Regards
Darryn
 
Darryn,

I'm a C# newbie myself, and I want to preface this by admitting I have no
idea what I'm talking about.

But, I've had success setting column widths using code similar to yours,
except I set the databinding on the DataGrid first, then did the
DataGridTableStyle stuff. Maybe the order matters?

I sense that the code you provided is condensed, and your real code uses
more than one column, right? Because you said "the columns are all
squashed", _columns_ (plural), and yet your code only puts a single column
in the grid.

Note that the DataGridTableStyle object also has a field called
PreferredColumnWidth, or something like that, that may be of interest to
you.

Patrick


Hi,

When i popualte my datagrid the columns are all squashed together and not
applying their set width.. my code is as follows..

first i do this..

DataGridTableStyle TSCA = new DataGridTableStyle() ;
TSCA.MappingName = "tbl" ;

DataGridColumnStyle TCCode = new DataGridTextBoxColumn() ;
TCCode.MappingName = "Code" ;
TCCode.HeaderText = "Code" ;
TCCode.Width = 11 ;
TSCA.GridColumnStyles.Add(TCCode) ;

dgCA.TableStyles.Add(TSCA) ;

then i do this...

CConnection.ConnectionString = StrConnectionPath ;
CConnection.Open() ;

SelectLstCommand.CommandText = "Select * From tbl" ;
SelectLstCommand.Connection = CConnection ;
CAdapter.SelectCommand = SelectLstCommand ;
CAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey ;
CAdapter.Fill(CDs, "tbl") ;
dgCA.SetDataBinding(CDs, "tbl") ;
CConnection.Close() ;

Any help would be appreciated.

Regards
Darryn
 

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

Back
Top