Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change DataGridView Cell Border

Status
Not open for further replies.

ousoonerjoe

Programmer
Jun 12, 2007
925
US
Using VB.Net 2010.

After wading through the swamp of MSDN files, I realized I've been traveling in circles all morning. When using a DataGridView, I want to allow the user to place a comment "under" the cell (storing it in the ToolTipText). I'd like to be able to adjust the cell's borders to indicate there is a comment in it. The following is what I'm trying to achieve, but failing miserably.
Code:
                dgAsyLine.Rows(RowIndex).Cells(ColumnIndex).Style = DataGridViewCellBorderStyle.Raised

[COLOR=green]Generates Error: Error    1    Value of type 'System.Windows.Forms.DataGridViewCellBorderStyle' cannot be converted to 'System.Windows.Forms.DataGridViewCellStyle[/color]

I've been using the following, but the refresh rates with it running in CellPainting are not playing well with others, which is why I want to move to actually setting the cell directly and not having to depend on the paint to do it. The grid is used for displaying scheduling information. (It's large and highly colorful).
Code:
    Private Sub dgAsyLine_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles dgAsyLine.CellPainting
        If e.RowIndex > 0 And e.ColumnIndex > 0 Then
            If dgAsyLine.Item(e.ColumnIndex, e.RowIndex).ToolTipText.Length > 0 Then
                e.Paint(e.ClipBounds, e.PaintParts)
                ControlPaint.DrawBorder3D(e.Graphics, e.CellBounds, Border3DStyle.Raised)
                e.Handled = True
            End If
        End If
    End Sub

--------------------------------------------------
Stubbornness is a virtue -- if you are right. --Chuck Noll
--------------------------------------------------
 
Unfortunately, I'm back to re-addressing this issue. The CellPainting is unable to handle the visible result. When the cell in question comes into view, the cell does have a raised border, but the texts and colors are garbled up making it illegible as if the paint is not in effect for anything other than the border.

Any ideas on how to correct this? Ideally, I'm already having to loop through the grid programmaticly, and setting the specific cell's border then would be best. However, I don't see a way to set the border at run-time for a specific cell.

Any assistance is appreciated.

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top