Click here to Skip to main content
16,013,082 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: custom property at cell level for a datagird vb.net Pin
rasnarakesh11-Jun-10 2:08
rasnarakesh11-Jun-10 2:08 
GeneralRe: custom property at cell level for a datagird vb.net Pin
Dave Kreskowiak11-Jun-10 2:26
mveDave Kreskowiak11-Jun-10 2:26 
GeneralRe: custom property at cell level for a datagird vb.net Pin
rasnarakesh11-Jun-10 2:42
rasnarakesh11-Jun-10 2:42 
GeneralRe: custom property at cell level for a datagird vb.net Pin
rasnarakesh11-Jun-10 2:43
rasnarakesh11-Jun-10 2:43 
GeneralRe: custom property at cell level for a datagird vb.net Pin
Henry Minute11-Jun-10 6:24
Henry Minute11-Jun-10 6:24 
GeneralRe: custom property at cell level for a datagird vb.net Pin
rasnarakesh13-Jun-10 19:44
rasnarakesh13-Jun-10 19:44 
GeneralRe: custom property at cell level for a datagird vb.net Pin
Henry Minute14-Jun-10 0:24
Henry Minute14-Jun-10 0:24 
GeneralRe: custom property at cell level for a datagird vb.net Pin
rasnarakesh16-Jun-10 20:52
rasnarakesh16-Jun-10 20:52 
Sorry henry,

I tried your 2 ways but the performance is very slow that to painting at cell by level cannot be done if cellpainting event is used beceause if boder color for two or three cell is selected at runtime then cell painting event ovverides other two colors and paint only the last color.So for this i used arrays and tried but the performance is too slow not only that it is not working properly if scrool bar is there .
I may be missing some thing please correct me if iam wrong anywhere.
I will post the code that i have did
Imports System.ComponentModel
Imports System.Windows.Forms

Public Class gridcustom
    Inherits System.Windows.Forms.DataGridView

    Private mOldColor As Color  ' Original button color
    Private mMOColor As Color   ' Mouse Over color
    Private selBorderColor As Color   ' Mouse Over color
    Private cellwidth As Single ' Original button color
    Private Selcellwidth As Single ' Original button color
    'Private RowValue As Integer() ' Original button color
    'Private ColValue As Integer() ' Original button color
    ' Dim i, j As Integer
    Dim i As Integer
    Dim j As Integer
    Dim k As Integer
    Dim Colrcount As Integer
    Dim Cellscount As Integer
    Dim a(0, 0) As TwoDColor
    Dim b(0, 0) As TwoDCell
    Dim selcolorcountarray As New ArrayList()
    Dim selWidthcarray As New ArrayList()
    Dim SelRowcountarray As New ArrayList()
    Dim selcolcountarray As New ArrayList()

    Dim selcolorcount(100) As Color
    Dim Widthcount(100) As Single
    Dim SelRowcount(100) As Integer
    Dim selcolcount(100) As Integer
    Private RowValue As Integer ' Original button color
    Private ColValue As Integer ' Original button color

    ' <System.ComponentModel.Category("Appearance")> _
    Property BorderColorForAllcells() As Color
        Get
            BorderColorForAllcells = mMOColor
        End Get
        Set(ByVal Value As Color)
            mMOColor = Value
        End Set
    End Property

    Property BorderWidthForAllcells() As Single

        Get
            BorderWidthForAllcells = cellwidth
        End Get
        Set(ByVal Value As Single)
            cellwidth = Value

        End Set
    End Property

    Property BorderColorSelectedcells() As Color

        Get
            BorderColorSelectedcells = selBorderColor
        End Get
        Set(ByVal Value As Color)
            selBorderColor = Value 
        End Set
    End Property
  

    Property BorderWidthForSelectedcells() As Single

        Get
            BorderWidthForSelectedcells = Selcellwidth
        End Get
        Set(ByVal Value As Single)
            Selcellwidth = Value
            selWidthcarray.Add(Selcellwidth)
        End Set
    End Property

    Property RowValueSelectedcells() As Integer

        Get
            RowValueSelectedcells = RowValue
        End Get
        Set(ByVal Value As Integer)
            RowValue = Value
            SelRowcountarray.Add(RowValue)           
        End Set
    End Property

    Property ColumnValueSelectedcells() As Integer

        Get
            ColumnValueSelectedcells = ColValue
        End Get
        Set(ByVal Value As Integer)
            ColValue = Value           
            selcolcountarray.Add(ColValue)
        End Set
    End Property
 


    Private Sub dataGridView1_CellPainting(ByVal sender As Object, _
  ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles MyBase.CellPainting


        If ((e.State And DataGridViewElementStates.Selected) = DataGridViewElementStates.Selected) Then
            Return
        End If
        If e.ColumnIndex >= 0 AndAlso e.RowIndex >= 0 Then
            DRAWCELL(mMOColor, e.RowIndex, e.ColumnIndex, cellwidth, e)
        End If

        If (selcolorcountarray.Count >= 1) Then
            If (selcolorcountarray.Item(0) = (Color.Empty) And selcolcountarray.Item(0) = 0 And SelRowcountarray.Item(0) = 0) Then
                selcolorcountarray.RemoveAt(0)
                selcolcountarray.RemoveAt(0)
                SelRowcountarray.RemoveAt(0)
            End If
            If (selcolorcountarray.Count >= 1 And k < selcolorcountarray.Count) Then
                'If (selcolorcountarray.Item(0)<> color.Empty ) Then
                If e.ColumnIndex = CType(selcolcountarray.Item(k), Integer) AndAlso e.RowIndex = CType(SelRowcountarray.Item(k), Integer) Then

                    If (selWidthcarray.Count <= k) Then
                        selWidthcarray.Add(0.0)
                    End If

                    DRAWCELL(selcolorcountarray.Item(k), e.RowIndex, e.ColumnIndex, selWidthcarray.Item(k), e)
                    k = k + 1
                    If (k = selcolorcountarray.Count) Then
                        k = 0
                    End If

                End If

            End If

        End If

          End Sub


    Private Sub DRAWCELL(ByVal c As Color, ByVal row As Integer, ByVal col As Integer, ByVal width As Single, ByVal e As DataGridViewCellPaintingEventArgs)

        Dim newRect As New Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1, _
                e.CellBounds.Width - 4, e.CellBounds.Height - 4)
        Dim backColorBrush As New SolidBrush(e.CellStyle.BackColor)
        Dim ForeColorBrush As New SolidBrush(e.CellStyle.ForeColor)
        Dim gridBrush As New SolidBrush(Me.GridColor)
        Dim gridLinePen As New Pen(gridBrush)
        Dim color As New System.Drawing.Pen(c, width)
        Try
            ' Erase the cell.
            e.Graphics.FillRectangle(backColorBrush, e.CellBounds)

            ' Draw the grid lines (only the right and bottom lines;
            ' DataGridView takes care of the others).
            e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, _
                e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, _
                e.CellBounds.Bottom - 1)
            e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, _
                e.CellBounds.Top, e.CellBounds.Right - 1, _
                e.CellBounds.Bottom)

            ' Draw the inset highlight box.
            e.Graphics.DrawRectangle(color, newRect)


            '' Draw the text content of the cell, ignoring alignment.
            If (e.Value IsNot Nothing) Then
                e.Graphics.DrawString(CStr(e.Value), e.CellStyle.Font, _
                ForeColorBrush, e.CellBounds.X + 2, e.CellBounds.Y + 2, _
                StringFormat.GenericDefault)
            End If
            ' e.PaintContent(e.CellBounds)
            e.Handled = True



        Finally
            gridLinePen.Dispose()
            gridBrush.Dispose()
            backColorBrush.Dispose()
        End Try

    End Sub

    End Class
        End Sub   

End Class



Code in form class
 Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim dt As New DataTable
       dt.Columns.Add(New DataColumn("column1", GetType(Integer)))
       dt.Columns.Add(New DataColumn("column2", GetType(String)))
       dt.Columns.Add(New DataColumn("column3", GetType(String)))
       dt.Columns.Add(New DataColumn("column4", GetType(String)))
       dt.Columns.Add(New DataColumn("column5", GetType(String)))



       Dim i As Integer
       For i = 0 To 10
           Dim dr As DataRow = dt.NewRow()
           dr("column1") = i
           dr("column2") = "item" & i.ToString()
           dr("column3") = "item" & i.ToString()
           dr("column4") = "item" & i.ToString()
           dr("column5") = "item" & i.ToString()
           dt.Rows.Add(dr)

       Next

       Me.Gridcustom1.DataSource = dt

   End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim intcount As Integer = 0
       For Each Row As DataGridViewRow In Gridcustom1.Rows
           If Gridcustom1.Rows(intcount).Cells(1).Value = "item0" Then
               Me.Gridcustom1.ColumnValueSelectedcells = 1
               Me.Gridcustom1.RowValueSelectedcells = intcount

               Me.Gridcustom1.BorderColorSelectedcells = Color.Chocolate
               'Me.Gridcustom1.Rows(intcount).DefaultCellStyle.BackColor = Color.Aqua

           End If
           If Gridcustom1.Rows(intcount).Cells(1).Value = "item1" Then
               Me.Gridcustom1.ColumnValueSelectedcells = 1
               Me.Gridcustom1.RowValueSelectedcells = intcount

               Me.Gridcustom1.BorderColorSelectedcells = Color.DarkBlue
           End If
           If Gridcustom1.Rows(intcount).Cells(0).Value = "4" Then
               Me.Gridcustom1.ColumnValueSelectedcells = 0
               Me.Gridcustom1.RowValueSelectedcells = intcount

               Me.Gridcustom1.BorderColorSelectedcells = Color.Green

           End If
           intcount += 1
       Next Row
   End Sub



Please correct me if iam wrong.

Thanks
Rasagna
QuestionDetermining if given DateTime is older than a Hour Pin
Member 44205349-Jun-10 21:04
Member 44205349-Jun-10 21:04 
AnswerRe: Determining if given DateTime is older than a Hour Pin
Scubapro9-Jun-10 22:18
Scubapro9-Jun-10 22:18 
AnswerRe: Determining if given DateTime is older than a Hour Pin
Luc Pattyn10-Jun-10 1:54
sitebuilderLuc Pattyn10-Jun-10 1:54 
AnswerRe: Determining if given DateTime is older than a Hour Pin
Anshul R10-Jun-10 19:53
Anshul R10-Jun-10 19:53 
GeneralRe: Determining if given DateTime is older than a Hour Pin
mvdcorput11-Jun-10 23:08
mvdcorput11-Jun-10 23:08 
QuestionHow to change reference path in VB6 Pin
Andraw Tang9-Jun-10 7:00
Andraw Tang9-Jun-10 7:00 
AnswerRe: How to change reference path in VB6 Pin
DaveAuld10-Jun-10 3:16
professionalDaveAuld10-Jun-10 3:16 
GeneralRe: How to change reference path in VB6 Pin
Andraw Tang10-Jun-10 3:24
Andraw Tang10-Jun-10 3:24 
GeneralRe: How to change reference path in VB6 Pin
DaveAuld10-Jun-10 3:42
professionalDaveAuld10-Jun-10 3:42 
GeneralRe: How to change reference path in VB6 Pin
Andraw Tang10-Jun-10 3:44
Andraw Tang10-Jun-10 3:44 
AnswerRe: How to change reference path in VB6 Pin
Anshul R10-Jun-10 19:59
Anshul R10-Jun-10 19:59 
QuestionWindows XP can't start my application Pin
O.G.I.9-Jun-10 1:04
O.G.I.9-Jun-10 1:04 
AnswerRe: Windows XP can't start my application Pin
Luc Pattyn9-Jun-10 2:07
sitebuilderLuc Pattyn9-Jun-10 2:07 
AnswerRe: Windows XP can't start my application Pin
Chris C-B9-Jun-10 3:11
Chris C-B9-Jun-10 3:11 
GeneralRe: Windows XP can't start my application Pin
O.G.I.9-Jun-10 4:21
O.G.I.9-Jun-10 4:21 
GeneralRe: Windows XP can't start my application Pin
Luc Pattyn9-Jun-10 5:37
sitebuilderLuc Pattyn9-Jun-10 5:37 
GeneralRe: Windows XP can't start my application Pin
Chris C-B9-Jun-10 5:42
Chris C-B9-Jun-10 5:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.