Manipulating a datagrid?

G

gsb58

Hi!
I'm using Visual Studio .NET 2003 (using C#).

On a form I have a datagrid where I've set the DataSource and
DataMember to receive values
from a view in a SQL 2000 database. It works fine.

However, I do want to change individual column's width.

Now I'v defined DataGridTableStyle Collection for each column, and I've
defined
DataGridColumnStyle Collection for each DataGridTableStyle.

I've set the respective widths but at run time it gives the default
width (preferredColumnWidth)
for each column.

Do I need to produce any code to manipulate the settings I've done?

I have like (for the first column):

dtgtsFirstCol //DataGridTableStyle

and

dttbFirstCol //DataGridColumnStyle

Anybody that could guide me on this?

Me.Name
 
G

gsb58

Hi!

I solved the problem. It's all a matter of investigating the property
sheet!

I set the preferredColumnWidth to 150

and the RowheaderWidth to 0

However, grid refused to accept any smaller width than 15, but I got
the desired result.
 
G

gsb58

Hi!

I finally solved the mystery by setting the column widths.

Here is what I did:

I made a view with data from three tables and put it on the server in a
SQL database.

Then in my application on the form containing the datagrid I did the
following:

Choose -> TableStyles. Add a member and give it a name.

Make sure you set the RowHeadersVisible to false
(this will make the default column of the grid invisible),
if you don't want to
have the default column of the grid to show.

Set the MappingName to the view (in this case) and click the
GridColumnStyles
(Colloection) field and the ... button.

Now add as many columns that you need to show in the grid.

Give them unique names and HeaderText titles. Set the MappingName and
the width.

Click OK, OK and run the application.

And all I did was reading the help file a little and Voila!

Happy programming.

Me.Name
 

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