|
-
May 24th, 2009, 01:31 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] DataGridView Bold One Row
How can I modify this:
vb Code:
Content.Font = New Font("Verdana", 8, FontStyle.Bold)
So that in my datagridview it only makes the selected row bold when it is double clicked?
Whole Thing:
vb Code:
Private Sub Content_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Content.CellDoubleClick
row = e.RowIndex
If row >= 0 Then
Content.Font = New Font("Verdana", 8, FontStyle.Bold)
End If
End Sub
Thanks!
I am still very new to VB.NET, so I have MANY questions
-
May 24th, 2009, 01:38 PM
#2
Re: DataGridView Bold One Row
You will have to set that individual row's DefaultCellStyle, like so:
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim BoldRow As New DataGridViewCellStyle With {.Font = New System.Drawing.Font("Verdana", 8.0!, FontStyle.Bold)} Me.DataGridView1.Rows(rowindex).DefaultCellStyle = BoldRow End Sub
-
May 24th, 2009, 02:21 PM
#3
Thread Starter
Hyperactive Member
Re: DataGridView Bold One Row
Kool that works!
Now when I change rows by double clicking the previously bolded row stays bold, why is that?
vb.net Code:
Content.Font = New Font("Verdana", 8, FontStyle.Regular) ' I was expecting this row to make them all normal font...
Dim BoldRow As New DataGridViewCellStyle With {.Font = New System.Drawing.Font("Verdana", 8.0!, FontStyle.Bold)}
Content.Rows(row).DefaultCellStyle = BoldRow
I am still very new to VB.NET, so I have MANY questions
-
May 24th, 2009, 02:50 PM
#4
Re: DataGridView Bold One Row
It's because that row is no longer pointing to the DataGridView.RowsDefaultCellStyle anymore. You have given it a new custom CellStyle. So, you will have to reset the rows where you have given it a custom font to the DataGridView.RowsDefaultCellStyle again (or a new CellStyle, whichever suits your needs).
This is what I would do. Everytime you bold a row, add it to a class level variable called bolded rows. Then when you want to unbold those rows, you loop through that list and change their CellStyle. Like so:
vb.net Code:
Public Class Form1 Private BoldedRows As New List(Of DataGridViewRow) Private Sub DataGridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick Me.DataGridView1.Rows(e.RowIndex).DefaultCellStyle = New DataGridViewCellStyle With {.Font = New Drawing.Font("Verdana", 8.0!, FontStyle.Bold)} Me.BoldedRows.Add(Me.DataGridView1.Rows(e.RowIndex)) End Sub Public Sub ResetBoldedRows() For Each BoldRow As DataGridViewRow In Me.BoldedRows Me.DataGridView1.Rows(Me.DataGridView1.Rows.IndexOf(BoldRow)).DefaultCellStyle = Me.DataGridView1.RowsDefaultCellStyle Next Me.BoldedRows.Clear() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ResetBoldedRows() End Sub End Class
-
May 24th, 2009, 03:02 PM
#5
Thread Starter
Hyperactive Member
Re: DataGridView Bold One Row
I am still very new to VB.NET, so I have MANY questions
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
|