vensali
asked on
how to wrap a merged cells of datagridview column in vs2010 (vb.net)
Pls suggest on how to achieve this feature in vb.net (vs2010)
Can you be more descriptive in stating what you need? What you want to accomplish?
ASKER
I have a column in datagrid with merged cells. I need to wrap the text in merged cells. I am able to do the text wrapping unmerged cells
Can you post the code how you are merging and un-merging cells in your code
ASKER
Column to be merged in datagridview - 2
dgv1.Columns(2).Width = 200
dgv1.Columns(2).DefaultCel lStyle.Ali gnment = DataGridViewContentAlignme nt.MiddleC enter in form load event
If e.ColumnIndex = 2 AndAlso e.RowIndex <> -1 Then
Using gridBrush As Brush = New SolidBrush(Me.dgv1.GridCol or), backColorBrush As Brush = New SolidBrush(e.CellStyle.Bac kColor)
Using gridLinePen As Pen = New Pen(gridBrush)
' Clear cell
e.Graphics.FillRectangle(b ackColorBr ush, e.CellBounds)
' Draw line (bottom border and right border of current cell)
'If next row cell has different content, only draw bottom border line of current cell
If e.RowIndex < dgv1.Rows.Count - 1 AndAlso dgv1.Rows(e.RowIndex + 1).Cells(e.ColumnIndex).Va lue.ToStri ng() <> e.Value.ToString() Then
e.Graphics.DrawLine(gridLi nePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1)
End If
' Draw right border line of current cell
e.Graphics.DrawLine(gridLi nePen, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom)
' draw/fill content in current cell, and fill only one cell of multiple same cells
If Not e.Value Is Nothing Then
If e.RowIndex > 0 AndAlso dgv1.Rows(e.RowIndex - 1).Cells(e.ColumnIndex).Va lue.ToStri ng() = e.Value.ToString() Then
Else
e.Graphics.DrawString(CTyp e(e.Value. ToString, String), e.CellStyle.Font, Brushes.Black, e.CellBounds.X + 2, e.CellBounds.Y + 5, StringFormat.GenericDefaul t)
End If
End If
e.Handled = True
End Using
End Using
End If
dgv1.Columns(2).Width = 200
dgv1.Columns(2).DefaultCel
If e.ColumnIndex = 2 AndAlso e.RowIndex <> -1 Then
Using gridBrush As Brush = New SolidBrush(Me.dgv1.GridCol
Using gridLinePen As Pen = New Pen(gridBrush)
' Clear cell
e.Graphics.FillRectangle(b
' Draw line (bottom border and right border of current cell)
'If next row cell has different content, only draw bottom border line of current cell
If e.RowIndex < dgv1.Rows.Count - 1 AndAlso dgv1.Rows(e.RowIndex + 1).Cells(e.ColumnIndex).Va
e.Graphics.DrawLine(gridLi
End If
' Draw right border line of current cell
e.Graphics.DrawLine(gridLi
' draw/fill content in current cell, and fill only one cell of multiple same cells
If Not e.Value Is Nothing Then
If e.RowIndex > 0 AndAlso dgv1.Rows(e.RowIndex - 1).Cells(e.ColumnIndex).Va
Else
e.Graphics.DrawString(CTyp
End If
End If
e.Handled = True
End Using
End Using
End If
ASKER
dgv1.Columns(2).DefaultCel lStyle.Wra pMode = DataGridViewTriState.True
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks