Controlling row height in DataGridView

  • Thread starter Thread starter Richard Lewis Haggard
  • Start date Start date
R

Richard Lewis Haggard

Here are the goals:

1) Give the user the means whereby a row's height expands to display the
entire contents of its tallest cell.
2) Give the user the means whereby a row will shrink down to a single line.
3) Give the user the means whereby a row's height can be manually set by
dragging the row header's divider.

I can accomplish either 1 and 2 or 3 but not all 3 at the same time.

The interface for goals 1 and 2 is handled through a column that has a
button in it. When depressed, the code sets the tallest cell's
Style.WrapMode = DataGridViewTriState.True. When released, the WrapMode
state is set to False. This works but only if the DataGridView is set up so
that row height drag is disabled. If row height drag is enabled then the
WrapMode appears to have no effect.

Would someone be so kind as to enlighten this rather confused programmer as
to which bits, flags and attributes must be set to what state in order for
the DataGridView to respond in the desired fashion? Thanks.
--
Richard Lewis Haggard
General: www.Haggard-And-Associates.com

Two fish are in a tank. One says to the other, "Are you absolutely position
that you know how to drive this thing?"
Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm
 
Probably you need to disable manual drag before setting 1 and 2. Then you
resize and enable manual resizing again.
HTH
 
Yeah, tried that first thing. There were problems. More information:

The app starts with the DateGridView in AutoSizeRowsMode =
DataGridViewAutoSizeRowsMode.None. This allows manual resize.

During expand/contract operation, the mode is changed to
DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders and then the cell's
WrapMode is set to True or False, depending. Upon completion, the grid goes
back to AutoSizeRowsMode of None.

There are problems with this. First of all, if the grid isn't forced to
immediately refresh, it ignores the row height changes. Even if it does the
refresh, the row height first expands and then contracts again.

Maybe I should try something slightly different - What are the sequence of
operations that the grid goes through to determine how tall the row has to
be? Since that works automatically, maybe I should just duplicate that
functionality and leave the system in a state fit for manual resize. I could
easily figure out the text extents for a normal text cell but that's not
what I'm using. I have created a RichTextBox column and this is the one that
can be the multi-line height. How do I figure out how tall a RichTextBox
cell needs?
 
I solved the problem of figuring out how tall a row must be to display the
entire contents of a RichText cell by creating a method that, when supplied
with a width, can calculate the height required to display RichTextBox's
contents. The single line contracted mode is satisfied by saving the height
of the new row when the form is first loaded. Thanks anyway, guys.
--
Richard Lewis Haggard
General: www.Haggard-And-Associates.com

911, what's the nature of your emergency?
"Oh my god! Please help! I accidentally shot my friend! It's really bad! I
think he may be dead!"
"Calm down, sir. This is important. Are you sure he's dead?"
The caller puts the phone down. After a moment, the 911 operator hears a
loud Bang
The caller returns. "OK, now what?"

Please come visit here for a couple thousand good giggles!:
www.haggard-and-associates.com/Humor/humor.htm
 
Back
Top