[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Draw diagonal lines in cell of DataGrid

Posted on 2006-06-06
7
Medium Priority
?
611 Views
Last Modified: 2008-02-01
Instead of graying out datagrid cells with a gray color, I would like to gray them out by drawing diagonal lines in the cell. How can I do this? Any ideas.

This is a windows forms application

SannQuest
0
Comment
Question by:Sanmarie
  • 4
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16845560
.NET version?

Bob
0
 

Author Comment

by:Sanmarie
ID: 16846811

.NET Version 1.1. Visual Studio 2003
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16851328
1) You need to define your own class, inheriting from DataGridTextBoxColumn, and handle the paint yourself.

2) Here is an example of what I mean:

Public Class DataGridColorTextBoxColumn
  Inherits DataGridTextBoxColumn

  Private m_maxColumn As DataGridColorTextBoxColumn
  Public Property MaxValueColumn() As DataGridColorTextBoxColumn
    Get
      Return m_maxColumn
    End Get
    Set(ByVal Value As DataGridColorTextBoxColumn)
      m_maxColumn = Value
    End Set
  End Property


  Private m_source As CurrencyManager

  Private Function GetRowValue(ByVal rowNumber As Integer) As String
    Return Me.GetColumnValueAtRow(m_source, rowNumber)
  End Function


  Protected Overloads Overrides Sub Paint(ByVal g As Graphics, _
   ByVal bounds As Rectangle, ByVal source As CurrencyManager, _
   ByVal rowNum As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal alignToRight As Boolean)

    Try

      If Me.MaxValueColumn Is Nothing Then
        Throw New ArgumentException("Max value column is not set.")
      End If

      m_source = source

      Dim columnValue As Double = Me.GetRowValue(rowNum)

      If columnValue > Me.MaxValueColumn.GetRowValue(rowNum) Then
        backBrush = New SolidBrush(Color.Green)
        foreBrush = New SolidBrush(Color.White)
      End If

    Catch ex As Exception

      MessageBox.Show(ex.ToString())

    Finally

      MyBase.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight)

    End Try


  End Sub

End Class

Bob
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Sanmarie
ID: 16851879
Thank you for the info.

I have already inherited from a datagridTextBoxColumn and I can set the color of any cell I want by overriding the paint method. But, instead of coloring a cell with a color by using
backbrush = new solidbrush(Color.Green)

I want to "color" the cell with diagonal lines running across it. How do I implement the diagonal lines? Do I have to use a pen object or something like that?

Thanks

Sanna
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 16851916
Since you have the Graphics instance, you could do something like this:

g.DrawLine(Pens.DarkGray, 20, 20, 100, 100)

Bob
0
 

Author Comment

by:Sanmarie
ID: 16851991
Thanks.

I guess to get many diagonal lines, I could put this statement in a for loop, looping for less than the height of the cell. I will try it and let you know.

Sanna
0
 

Author Comment

by:Sanmarie
ID: 16852312

It works. Thanks a lot

Sanna
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question