Click here to Skip to main content
15,891,936 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Private Sub SolidListDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles SolidListDataGridView.CellContentClick



        'to access the object for changing the color

        Dim j = SolidListDataGridView.CurrentRow.Index
        Dim Hi As Object = SolidListDataGridView.Item(4, j).Value
        Dim doc As Document =
        Dim App As Object = 
        Dim targetObject As Object
        targetObject = App.activedocument.handleToObject(Hi)

        'changing object color to index 60 during it choose from gridview
        targetObject.color = 60
Posted
Comments
j snooze 20-Aug-15 17:33pm    
Not sure if I understand your question. But if you just make it the CellClick event instead of the content click event and then

Dim cell As DataGridViewCell
cell = SolidListDataGridView.CurrentCell
cell.Style.BackColor = Color.Aqua

that should work.
Member 11907819 21-Aug-15 2:29am    
Dear J,
thank you for your Follow.
i made an application for Autocad which make a list(as grid-view) from all object you have in drawing, each object in drawing has an odd Id or handle, therefore what i need to do is: when i choose one of this handles (from grid-view), temporary highlight(change the color)of related object in drawing area.
I know some how how to change the color of drawing item the think i am looking for is how to make this loop of highlight item temporary during it choose in gridwiew and after i choose an other on it go back to first situation
j snooze 21-Aug-15 16:56pm    
Just store your current cell row and column in a module/class level variable. Then on the cell click turn that cell white, and the newly selected cell the new color.
Member 11907819 23-Aug-15 17:06pm    
would you please be so kind and make an example or show me an reference to study about that
thank you

1 solution

Dear J,
i found the solution as below do you have better idea because in the case below i should find the base color of objects at first and save it in new column (No.5)and after change the row psition do one more transaction to rolle it back to first color

Public Class Highlight

 'the process of row which leave
'------------------------------------------
Private Sub SolidListDataGridView_CellLeave(sender As Object, e As DataGridViewCellEventArgs) Handles SolidListDataGridView.CellLeave

        Dim z As Integer = SolidListDataGridView.CurrentRow.Index


        Dim lld2 As String = SolidListDataGridView.Item(4, z).Value
        Dim col As Double = SolidListDataGridView.Item(5, z).Value

        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim acadApp As Object = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
        Dim acCurDb As Database = doc.Database
        Dim Cur As AcadObject
        Cur = acadApp.activedocument.handleToObject(lld2)
 
'this transaction reset the color of object to first situation

        Using Trans2 As Transaction = acCurDb.TransactionManager.StartTransaction()

            Cur.color = col
            Trans2.Commit()
        End Using

    End Sub

    'the action on current row 
'------------------------------------------
Private Sub SolidListDataGridView_MouseDown(sender As Object, e As DataGridViewCellEventArgs) Handles SolidListDataGridView.CellClick

        Dim i As Integer = SolidListDataGridView.CurrentRow.Index

        Dim lld1 As String = SolidListDataGridView.Item(4, i).Value


        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim acadApp As Object = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
        Dim acCurDb As Database = doc.Database

        Dim Cur As AcadObject
        Cur = acadApp.activedocument.handleToObject(lld1)
 
   'this transaction change the color of object 

        Using Trans1 As Transaction = acCurDb.TransactionManager.StartTransaction()

            Cur.color = 150
            Trans1.Commit()
        End Using
    End Sub
end class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900