Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am populating data from data base into a data grid. What I want is that the column resize them selves according to the length of the data that they get from the data base. Please do let me know if there is a way I can do this. Some thing like Autoresizing for the data grid.

 

Thanks

Posted

I dont think so.......

 

You have to specify the column widths yourself using a tablestyle.

Dream as if you'll live forever, live as if you'll die today
  • 4 weeks later...
Posted

You might try the following .

If you create your own class and inherit DataGridTextBoxColumn, then overide the paint method and in this work out the length of the text in the cell and if it exceeds the column width then increase the column width appropriately. I think you can get at it in the paint method using Me.DataGridTableStyle.GridColumnStyles(0).Width.

 

Try and see if it works.

Hamlet
Posted

You could use the MeasureString method of a graphics object to get the pixel width of each entry in the column, and then compare that to the column's width.

Dim G as Graphics = me.CreateGraphics
Dim str as String = "abcdefg"  '<-- example string
Dim pixelWidth as Integer = G.MeasureString(str, me.font).Width
If Column.Width <= pixelWidth Then Column.Width = pixelwidth
G.Dispose

I didn't actually thy this, but it might work.

"It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve."

 

- Edgar Allan Poe, 1841

 

I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker.

 

- Helen Keller

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...