By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,009 Members | 2,821 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,009 IT Pros & Developers. It's quick & easy.

DataGridView - how to toggle multiline on a row?

P: n/a
I have a DataGridView which has a cell that is going to contain what might
be a large amount of text data. The UI designed has decreed that each row
will have a button that toggles the row's multiline display such that, when
the button is up, the row is a single line and when the button is down, the
row enters a multiline mode so that the cell can expand to a height great
enough to display all of the cell's contents. I've figured out how to make a
column of buttons but the toggling between multi and single line is giving
me trouble. How can this be done?
--
Richard Lewis Haggard
www.Haggard-And-Associates.com
Mar 20 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Here is one way you can attempt to do this. Handle the CellPainting
event. In your event handler, somehow test whether the cell being
painted is one of your potential multiline cells (not sure how you
would do this in your particular case, but you would have the row and
column index among other properties that you could use in your test).
If the cell should be multiline, then set the WrapMode property. Then,
finally, in your button click code, you would some how make the grid
refresh itself (maybe calling dataGridView.Refresh) so the cell would
be redrawn with the correct WrapMode setting. This way every time teh
cell is drawn, the proper WrapMode is dynamically determine.
void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex == 2 && e.RowIndex -1 &&
dataGridView1[0, e.RowIndex].Value.Equals("1"))
{
e.CellStyle.WrapMode = DataGridViewTriState.True;
}
}

===================
Clay Burch
Syncfusion, Inc.

Mar 20 '07 #2

P: n/a
On Mar 20, 1:50 pm, "ClayB" <c...@syncfusion.comwrote:
Here is one way you can attempt to do this. Handle the CellPainting
event. In your event handler, somehow test whether the cell being
painted is one of your potential multiline cells (not sure how you
would do this in your particular case, but you would have the row and
column index among other properties that you could use in your test).
If the cell should be multiline, then set the WrapMode property. Then,
finally, in your button click code, you would some how make the grid
refresh itself (maybe calling dataGridView.Refresh) so the cell would
be redrawn with the correct WrapMode setting. This way every time teh
cell is drawn, the proper WrapMode is dynamically determine.

void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex == 2 && e.RowIndex -1 &&
dataGridView1[0, e.RowIndex].Value.Equals("1"))
{
e.CellStyle.WrapMode = DataGridViewTriState.True;
}
}

===================
Clay Burch
Syncfusion, Inc.
I usually display multi-line text in a textbox within the cell, and
show/hide the textbox accordingly.
Another approach maybe using tooltip to display the full text if mouse
hover-over. There are
some custom tooltip out there.

Quoc Linh

Mar 20 '07 #3

P: n/a
This worked great. Thanks!
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

"ClayB" <cl***@syncfusion.comwrote in message
news:11*********************@o5g2000hsb.googlegrou ps.com...
Here is one way you can attempt to do this. Handle the CellPainting
event. In your event handler, somehow test whether the cell being
painted is one of your potential multiline cells (not sure how you
would do this in your particular case, but you would have the row and
column index among other properties that you could use in your test).
If the cell should be multiline, then set the WrapMode property. Then,
finally, in your button click code, you would some how make the grid
refresh itself (maybe calling dataGridView.Refresh) so the cell would
be redrawn with the correct WrapMode setting. This way every time teh
cell is drawn, the proper WrapMode is dynamically determine.
void dataGridView1_CellPainting(object sender,
DataGridViewCellPaintingEventArgs e)
{
if (e.ColumnIndex == 2 && e.RowIndex -1 &&
dataGridView1[0, e.RowIndex].Value.Equals("1"))
{
e.CellStyle.WrapMode = DataGridViewTriState.True;
}
}

===================
Clay Burch
Syncfusion, Inc.

Mar 21 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.