?
Solved

VB.NET - Dynamically adjusting column widths in datagrid

Posted on 2007-08-12
7
Medium Priority
?
334 Views
Last Modified: 2008-02-01
Hi,
I'm creating an application in VB.NET. I've created a datagrid to display records from my database.

This datagrid will actually be showing data from different tables, depending on table the user wishes to view, so i'm creating and configuring the data adapter and dataset via code and then refreshing the datagrid.

I have a function which runs every time a user selects to display a table on the datagrid. It's a simple function that dynamically creates the datagridtextcolumns based on the number of columns in the table in the dataset. So far, the program works well.

However, the only part i'm having a problem with is the column width. I need to dynamically be able to adjust the width of the colum for each datagridtextcolumn, to fit the longest entry in that column. Any ideas on how this can be accomplished?

Best Regards,
CV.
0
Comment
Question by:connelvalentine
  • 4
  • 2
7 Comments
 
LVL 6

Expert Comment

by:hatem72
ID: 19678585
0
 

Author Comment

by:connelvalentine
ID: 19678720
HI hatem72,

Unfortunately, i'm still using VB.NET 2002.
I understand that the datagridview control has replaced the datagrid control in later versions of VB.NET. I'm looking for a solution that will work with just a datagrid control.

OR, i'm even open to any suggestions on how it can be possible to use the datagridview control in the VB.NET version i have. If this is possible, will i have to take any precautions while distributing my application later?

Best Regards,
CV
0
 
LVL 6

Expert Comment

by:hatem72
ID: 19678730
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 18

Expert Comment

by:vbturbo
ID: 19678737
For datagrid   net 1.1 check this solution
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q877q

vbturbo
0
 
LVL 6

Accepted Solution

by:
hatem72 earned 1500 total points
ID: 19678742
0
 

Author Comment

by:connelvalentine
ID: 19679144
Hi Hatem72,

This solution almost seems to be working from the dotnet247 link, but i'm having some problems understanding the code to tweak it a bit:

Dim size As SizeF
Dim sf As StringFormat = New StringFormat(StringFormat.GenericTypographic)
size = g.MeasureString(dtgr_database(i, col).ToString(), dtgr_database.Font, 500, sf)

This is just a small snippet i've taken out from the code. Could you please explain what these lines of code mean? They're pretty greek to me and the VS help wasn't too helpful.

BR,
CV.
0
 
LVL 6

Expert Comment

by:hatem72
ID: 19684060
Hi,

First thanx for [B] ... about that code snippet ... it's search result & i am working
with vb 2005 ... i am sory ... BUT good thing that snippet [almost seems to be working ] .
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question