473,324 Members | 2,456 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,324 software developers and data experts.

DataGridView - how to toggle multiline on a row?

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
3 24961
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Art | last post by:
Hi, I'm having some trouble with my DataGridView. I have it bound to a DataTable. One column of the grid is a boolean that says whether a row should be visible. There is also a checkbox...
0
by: lv2compute | last post by:
I am having a problem with my datagridview. I have a small table that has two columns. The first column is bound to my dataset. The second column is a combobox. I add items to the combobox based on...
1
by: jon.paine | last post by:
Hi All - I'm working on my first real c# windows forms - but I've done c# web development for awhile. The problem that I'm running into is with defining a layout structure for a dataGridView...
7
by: BillE | last post by:
What is the best way to add data using a DataGridView in a multi-tier application (data entry is handled in a data access layer using stored procedures)? Thanks Bill
2
by: =?Utf-8?B?UmljaA==?= | last post by:
I have code to bold text in a datagridviewcell: Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim cs As DataGridViewCellStyle, fnt...
3
by: Bill Nguyen | last post by:
I can't figure out how to identify/display the column header name in Mouseclick event. This is a checkbox column type and I would like all cells in this column to toggle checked/unchecked when the...
0
by: Alcibiade | last post by:
Hi, I have 2 questions: 1)if width datagridview is shorter than form witdh, user will see horizontal scrollbar to see all grid.How can I adapt width form to width datagridview? 2) If a cell...
0
by: Steve K | last post by:
to this newline when an enter key is detected. Update: I tried adding this code: <code> public PMDDataGridViewTextBoxEditingControl() :base() { this.Multiline = true; } </code>
0
by: evilson | last post by:
Hi, I have two textbox, one of the textbx is is set to multiline. Problem is when i try to insert the value of the multiline textbox to the datagridview, it never work. The datagrid's warpmode is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.