472,969 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,969 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 24894
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.