如何在Gridview中处于​​选择模式之前更改对象颜色 [英] how can I change the object Color until it is in selection mode in gridview

查看:46
本文介绍了如何在Gridview中处于​​选择模式之前更改对象颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 私有  Sub  SolidListDataGridView_CellContentClick( ByVal  sender  As  System。 Object  ByVal  e  As  System.Windows.Forms.DataGridViewCellEventArgs)句柄 SolidListDataGridView.CellContentClick 



' 访问对象以更改颜色

Dim j = SolidListDataGridView.CurrentRow.Index
Dim 您好作为 对象 = SolidListDataGridView.Item( 4 ,j).Value
Dim doc 作为文档=
Dim App As 对象 =
Dim targetObject As 对象
targetObject = App.activedocument.handleToObject(Hi)

' 在从gridview中选择时将对象颜色更改为索引60
targetObject.color = 60

解决方案

亲爱的J,

i发现以下解决方案你有更好的主意,因为在下面的情况下我应该找到首先将对象的基本颜色保存在新列(No.5)中,然后在更改行psition后再执行一次事务以将其回滚到第一种颜色



公共类突出显示

'程序离开
'的行的ss ---------------------------------------- -
Private Sub SolidListDataGridView_CellLeave(sender As Object,e As DataGridViewCellEventArgs)处理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)

'此事务将对象的颜色重置为第一种情况

使用Trans2 As Transaction = acCurDb.TransactionManager.StartTransaction( )

Cur.color = col
Trans2.Commit()
结束使用

结束子

'当前行的行动
'------------------------------------------
私人Sub SolidListDataGridView_MouseDown(sender As Object,e As DataGridViewCellEventArgs)处理SolidListDataGridView.CellClick

Dim i As Integer = SolidListDataGridView.CurrentRow.Index

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


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事务更改对象的颜色

使用Trans1 As Transaction = acCurDb.TransactionManager.StartTransaction()

Cur.color = 150
Trans1.Commit()
End using
End Sub
end class


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

解决方案

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


这篇关于如何在Gridview中处于​​选择模式之前更改对象颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆