|
-
Jan 12th, 2012, 09:00 AM
#5
Addicted Member
Re: How to merge cells in datagridview?
Hi Kevin - im coding in vb.net and am new at programming so am unable to convert ... any further suggestions? I've found some samples, eg...
Code:
Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
Dim y As Integer
For y = 0 To DataGridView1.Rows.Count - 1
If (e.ColumnIndex = 0 And e.RowIndex = y) Then
If Not IsNumeric(DataGridView1(0, y).Value) Then ' for instance i wanted to make something like band end merged with the next cell(s.t.h. like header band )
e.AdvancedBorderStyle.Right = DataGridViewAdvancedCellBorderStyle.Single
End If
e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.Single
End If
If (e.ColumnIndex = 1 And e.RowIndex = y) Then
If y > 0 Then
If DataGridView1(1, y).Value = DataGridView1(1, y - 1).Value Then
Else
e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.Single
End If
End If
End If
Next
End Sub
This is fine, but ideally, I'd like the merged cells to look like cells that are merged in excel, ie, just one line of text, centred in the merged cells, rather than the same thing repeated in all rows...(hope that makes sense)
help is greatly appreciated
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|