473,385 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Resizing dataGridView rows and columns

I have a DataGridView that has potentially several hundred rows
(possibly a thousand or two).
I'd like for each row to have the proper height to accomadate the text
in the row. I tried setting the AutoSizeRowMode to AllCells. This
worked great on small datasets, but the program hung for a long time on
larger datasets.

I changed it to DisplayedCells, but this has some quirks: All of the
initally displayed rows are the correct height (for the text they
contain), but when I scroll, all other rows are about 1 line of text
tall (but most cells in fact contain up to 3 lines of text).
I can get the displayed cells to adjust to the correct height, but only
if I make some other change to the datagrid, such as adjusting the
column width. This event seems to force an autoresize. Unfortunately,
I'd rather have an an autoresize take place when I scroll.
I added the following code to the scroll even handler:

Me.searchResult_Grid.AutoResizeRows(DataGridViewAu toSizeRowsMode.DisplayedCellsExceptHeaders)

But it doesn't seem to have an effect.

Actually, I'd rather have the autoresize when I STOP scrolling, but
"If e.Type = ScrollEventType.EndScroll Then" doesn't seem to do
anything.

Another problem I'm having with column sizing:
The client wants the columns to fit the data (shouldn't be too hard
with the proper AutosizeMode) but also wants to be able to manually
resize them. I just can't seem to get this to work. If I set the
columnAutosizeMode to initially be AllCells, then the column widths are
perfect, but the user cannot manually adjust. If I set it to None, then
the columns are all the same width, but the user CAN manually adjust.
Is it even possible to do this?

Nov 24 '06 #1
2 11457
Forget to mention:
with regards to the column resize problem, I DID set
allowUserToResizeColumns to True, but when AutoSizeColumnMode is set to
AllCells, I cannot actually resize the columns.

Nov 24 '06 #2
I added this code to the scroll event handler:

If e.Type <ScrollEventType.ThumbTrack AndAlso e.ScrollOrientation =
ScrollOrientation.VerticalScroll Then

Me.searchResult_Grid.AutoResizeColumns(DataGridVie wAutoSizeColumnsMode.DisplayedCells)

End If

I came to it mostly by trial and error :S
It seems to work ok for what I need but still seems a bit hackish. Can
anyone out there offer more insight into DataGridView row and column
resizing?

Nov 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Art | last post by:
Hi, Forgive me for posting this message in 2 groups -- it appears that the Data Access group isn't very active, so I'm posting again here: I have a DataTable that I want to fill using a...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
2
by: Rich | last post by:
Hello, Following an example at http://www.vb-tips.com/dbpages.aspx?IA=DG (by Cor Lightert and Ken Tucker) on binding a dataRelation to a Datagridview for sqlClient, I was able to view rows...
3
by: steve | last post by:
Hi All How can I get the datagridview to redraw after changing the rowtemplate.height at runtime ( it is databound to a datatable) I have tried datagridview1.refresh etc to no avail (The row...
3
by: sklett | last post by:
I'm changing from a DataGrid to a DataGridView and have run across a problem. The items that are bound to the DataGrid have an int Property that represents a primary key of a lookup table in my...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
1
by: TG | last post by:
Hi! I have an application in which I have some checkboxes and depending which ones are checked those columns will show in the datagridview from sql server or no. After that I have 2 buttons:...
6
by: Miro | last post by:
Sorry for the cross post. I am stuck. I have a datagridview for poker rounds. Basically there are 3 columns in this datagridview. "Round" "SmallBlind" "BigBlind" I have an issue when I tab...
1
by: Zack00000 | last post by:
Hi, Is there a way to optimize the DataGridView in terms of drawing speed? The application that I'm building will need to use multiple datagridview controls which will get updated around every...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.