Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid - anchoring columns or autosizing columns?

Status
Not open for further replies.

tahirk

Programmer
Oct 24, 2005
47
GB
Hi,

I have spent the last hour trying to workout how I can autosize or anchor the columns so when I resize the main form, the grid is also resized, not just the component.

The only thing I have been able to do is to anchor the DataGrid component to the form so that it resizes correctly with the form however the grid and columns stay in the same place.

I want the grid to resize as well, is this even possible? I amazed such an important feature is missing! I am looking at another possibility and that is to use a an Open Source datagrid component developed by Davide Icardi.

Any ideas?

Thanks in advance,

Fz
 
Capture the Form.Resize event and you'll have to recalculate the column widths based on the new width.
 
JunkMoneky,

Thanks for the tip, I tried that method however it seems I the form does too many calculations as its continueously calling a fuction I created to compute the size of the columns.

I found out that this useful but missing feature is available in VS.NET 2005 as with partial classes whereby I could have just created my own event handler for the form.

I used this method [url ] and it worked great for me.

As I am using an XML file as my data source I am only using a few columns so what I did was to put a DataGrid on my form and a DataSet and then programmatically read in the XML into the DataSet.

Then I used the Microsoft method and added some lines in the Form Load event to resize the columns to the largest column size (at least made the data view legible); finally I cheated a bit as I still wanted the whole grid view to extend to the region of the client app so I simply set the last column width to the largest column and multiplied this number by a 1000 ;)

Now the last column is stretched right out so at least when I am reszizing the form now the grid fills the whole client space and not just a small corner.

Anyone know of a much better solution? I would ideally like to have the grid resize itself and its columns when I resize the form, much like what a proper grid control should do.

I have looked a 3rd party solution developed by Developer Express but the component prices are way too high for a solo developer like me.

Thanks,

Fz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top