This is a custom form for setting properties. At design time

Mansour_Dalir 2,036 Reputation points
2023-06-04T18:49:17.91+00:00

setProperty

hi

Please solve this problem, thank you

'_________(1)________________is Form Dialog For Change Properties
Public Class frmSetProperties
    Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

    Public dgv As uDgv

    Dim bitExitTextChenge As Boolean
    Public Sub _Load()

        dgvPro.Columns.Add("proName", "Property Name")
        dgvPro.Columns.Add("proValue", "Value")
        dgvPro.Columns(1).ValueType = GetType(String)
        dgvPro.Columns.Add("proHelp", "Help")
        dgvPro.Columns(0).Width = 160
        dgvPro.RowHeadersVisible = False
        dgvPro.SelectionMode = DataGridViewSelectionMode.FullRowSelect

        butCharType.BackColor = Color.FromArgb(224, 224, 224)
        ' dgvProperties._Load(inTableName:="settingTableProperties", PrimaryColumn:="id")
        
    End Sub

    Private Sub butOk_Click(sender As Object, e As EventArgs) Handles butOk.Click
        Dim pInfo As System.Reflection.PropertyInfo
        Dim a As Integer
        Try

            For a = 0 To dgvPro.RowCount - 1
                pInfo = dgv.GetType.GetProperty(dgvPro.Rows(a).Cells(0).Value)
                'MsgBox(pInfo.PropertyType.Name)
                Select Case pInfo.PropertyType.Name
                    Case "Color"
                        If dgvPro.Rows(a).Cells("proValue").Value Is DBNull.Value Then
                        Else
                            pInfo.SetValue(dgv, Color.FromArgb(dgvPro.Rows(a).Cells("proValue").Value))
                        End If
                    Case "String[]"
                        If dgvPro.Rows(a).Cells("proValue").Value Is DBNull.Value Then
                            ' pInfo.SetValue(obj, Nothing)
                        Else
                            '      ' Dim sObj As Object = Split(dr("propertyValue"), vbNewLine)
                            pInfo.SetValue(dgv, dgvPro.Rows(a).Cells("proValue").Value)
                            '  pInfo.SetValue(obj, dr("propertyValue"))
                        End If
                    Case GetType(Boolean).Name
                        If dgvPro.Rows(a).Cells("proValue").Value Is DBNull.Value Then
                        Else
                            pInfo.SetValue(dgv, CBool(dgvPro.Rows(a).Cells("proValue").Value))
                        End If
                    Case Else

                        If dgvPro.Rows(a).Cells("proValue").Value Is DBNull.Value Then
                            '  pInfo.SetValue(obj, Nothing)
                        Else
                            pInfo.SetValue(dgv, dgvPro.Rows(a).Cells("proValue").Value)
                        End If
                End Select
                ' pInfo.GetSetMethod(True)

            Next
            ''pInfo = dgv.GetType.GetProperty("a_RefreshNeed_DoubleClickMe")
            ''pInfo.SetValue(dgv, True, invokeAttr:=Reflection.BindingFlags.GetField, Nothing, {uDgv}, Nothing)

        Catch ex As Exception
            MsgBox(a & " " & pInfo.PropertyType.Name & vbNewLine & ex.Message)
        End Try
        dgv.Parent.Invalidate()
        dgv.Invalidate()
        Me.Invalidate()
        Me.SuspendLayout()


        'TAB>Home>A>Enter>TAB>Home>Del>Enter
        keybd_event(9, 0, 1, 0)
        keybd_event(9, 0, 2, 0)
        keybd_event(36, 0, 1, 0)
        keybd_event(36, 0, 2, 0)
        keybd_event(65, 0, 1, 0)
        keybd_event(65, 0, 2, 0)
        keybd_event(13, 0, 1, 0)
        keybd_event(13, 0, 2, 0)
        keybd_event(9, 0, 1, 0)
        keybd_event(9, 0, 2, 0)
        keybd_event(36, 0, 1, 0)
        keybd_event(36, 0, 2, 0)
        keybd_event(46, 0, 1, 0)
        keybd_event(46, 0, 2, 0)
        keybd_event(13, 0, 1, 0)
        keybd_event(13, 0, 2, 0)
    End Sub
End Class

'_________(2)___________Class for Dialog Custom Properties Form


Public Class claShowForm
    Inherits UITypeEditor
    Public Shared f As frmSetProperties
    Public Overrides Function GetEditStyle(context As ITypeDescriptorContext) As UITypeEditorEditStyle
        Return UITypeEditorEditStyle.Modal
    End Function
    Public Overrides Function EditValue(context As ITypeDescriptorContext, provider As IServiceProvider, value As Object) As Object
        Dim editorService = CType(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService)
        If (editorService IsNot Nothing) Then
            f = New frmSetProperties
            f.Text = context.PropertyDescriptor.Name
            Dim str1 As String = ""
            Dim b As UInt16
            Dim pInfo As System.Reflection.PropertyInfo
            Try
                f.dgv = context.Instance
                f.tssLblType.Text = "Type: " & context.PropertyDescriptor.PropertyType.Name
                f._Load()
                f.txtResult.Text = value
                Dim props() As System.Reflection.PropertyInfo = Me.GetType.GetProperties(BindingFlags.Public Or
              BindingFlags.Instance Or BindingFlags.DeclaredOnly)
                Dim pro() As Reflection.PropertyInfo = context.Instance.GetType.GetProperties(BindingFlags.Public Or
              BindingFlags.Instance Or BindingFlags.DeclaredOnly) 'context.Instance.GetType.GetProperties


                ' Dim i As Integer
                pInfo = context.Instance.GetType.GetProperty("Name")
                Dim vObj As Object

                vObj = pInfo.GetValue(context.Instance, Reflection.BindingFlags.GetProperty, Nothing, Nothing, Nothing)
                Dim strHelp As Reflection.ParameterAttributes = pInfo.Attributes()
                Dim idx As Integer = -1
                For b = 0 To pro.Length - 1
                    'i = InStr(pro(b).Name, "_")
                    '  If pro(b).Name <> "_backColor" Then
                    pInfo = context.Instance.GetType.GetProperty(pro(b).Name)
                        vObj = pInfo.GetValue(context.Instance, Reflection.BindingFlags.GetProperty, Nothing, Nothing, Nothing)
                    If pInfo.PropertyType.Name = "String[]" Then
                        str1 = Join(vObj, vbNewLine)
                    ElseIf pInfo.PropertyType.Name = "String" Then
                        str1 = CStr(vObj)
                    ElseIf pInfo.PropertyType.Name = GetType(DataGridView).Name Then
                    Else
                        str1 = CStr(vObj)
                    End If
                    If pInfo.PropertyType.Name <> GetType(DataGridView).Name Then
                        f.dgvPro.Rows.Add({pro(b).Name, str1})
                    End If


                Next
                'pInfo = context.Instance.GetType.GetProperty("_a1")
                ' pInfo.SetValue(context.Instance, "oook")
                ' f.dgvPro.Sort("", ListSortDirection.Ascending)
                For a = 0 To f.dgvPro.Rows.Count - 1
                    If f.dgvPro.Rows(a).Cells(0).Value = context.PropertyDescriptor.Name Then
                        'MsgBox(pro(a).Name & vbNewLine & context.PropertyDescriptor.Name)
                        f.dgvPro.CurrentCell = f.dgvPro.Item(0, a)
                        Exit For
                    End If
                Next

            Catch ex As Exception
                MsgBox(pInfo.PropertyType.Name & vbNewLine & " " & str1 & vbNewLine & ex.Message)
            End Try
            ' f.Show()
            If (editorService.ShowDialog(f) = DialogResult.OK) Then
                Dim sst As String = f.txtResult.Text
            End If
            claShowForm.f = Nothing
        End If
        Return value
    End Function
End Class

'______(3)_______on UserControl


 Structure sPropertis
        Dim bitRefresh As Boolean
        Dim RowValidtionOfParent As String
        Dim TextTitel As String
        Dim ReadyOnlyColumns As String
        Dim RightToLeft As Boolean
        Dim PrimaryKeyColumn As String
        Dim SelectCommand As String
        Dim PassWord As String
        Dim fullNameDataBase As String
        Dim TableName As String
        Dim NonVisibleColumns As String
        Dim ConnectionString As String
        Dim BeginIdxColumnInNewRow As String
        Dim filterColumns_For_TableQueries As String
        Dim ChildTable_ColumnName_PrimaryKey As String
        Dim FollowCurrentColumn As String
    End Structure
    Public Pro As sPropertis
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("حتما پس از تغییر اینجا را تغییر دهید" & vbNewLine & "وقتی از فرم ست پراپرتی استفاده میکنید حتما اینجا رفرش شود")>
    Public Property a_RefreshNeed_DoubleClickMe As Boolean
        Get
            Return Pro.bitRefresh
        End Get
        Set(value As Boolean)
            Pro.bitRefresh = value
        End Set
    End Property

    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("پیروی از ستون جاری" & vbNewLine & "گرفتن اعتبار (ستون جاری) از ستون جاری جهت جلوگیری از اشتباهات")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property FollowCurrentColumn As String
        Get
            Return Pro.FollowCurrentColumn
        End Get
        Set(value As String)
            Pro.FollowCurrentColumn = value
        End Set
    End Property
    'Previte([ChildTable Name] [Column Name Of ChildTable As Integer not Unique] [Column Nome of ParentTable As Integer but Unique]) DoubleClik(Column Nome of ParentTable as Any For Connect\Show)
    Const HelpChild As String = "dgvErtebatKala idItem id sumKMojodi,tedadKalayeMortabet"
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("ارتباط ستون (کلید اصلی) به جدول دیگر جهت بدست آوردن سطرهای فرعی" & vbNewLine &
    "Previte([ChildTable Name] [Column Name Of ChildTable As Integer not Unique] [Column Nome of ParentTable As Integer but Unique]) DoubleClik(Column Nome of ParentTable as Any For Connect\Show)" & vbNewLine &
    "ChildTable ChildTable.idItem ParentTable.id ParentTable.sumKMojodi,ParentTable.tedadKalayeMortabet")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property ChildTable_ColumnName_PrimaryKey As String
        Get
            Return Pro.ChildTable_ColumnName_PrimaryKey
        End Get
        Set(value As String)
            Pro.ChildTable_ColumnName_PrimaryKey = value
        End Set
    End Property
    ''' <summary>
    ''' نام ستون ها جهت فیلتر شدن تا در صورت ذخیره شدن سطر در جدول دیتابیس مورد خطا نشود.نکته فقط برای جداولی که ترکیبی از چند جدول می باشد
    ''' </summary>
    ''' <returns></returns>
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("فیلتر ستونها (جدول از نوع کیوری) جهت رفع خطا")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property FilterColumns_For_TableQueries As String
        Get
            Return Pro.filterColumns_For_TableQueries
        End Get
        Set(value As String)
            Pro.filterColumns_For_TableQueries = value
        End Set
    End Property
    'mogheyatha,faSharhMogheyat(notNull)=faSharhMogheyat,idMogheyat=id
    '[]
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("پیروی سطر از جدول والد" & vbNewLine & "گرفتن اعتبار (ستون/سطر) از جدول مشخص جهت جلوگیری از اشتباهات")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property RowValidtionOfParent As String
        Get
            Return Pro.RowValidtionOfParent
        End Get
        Set(value As String)
            Pro.RowValidtionOfParent = value
        End Set
    End Property
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("عنوان جدول" & vbNewLine & "kjk")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property TextTitel As String
        Get
            Return Pro.TextTitel
        End Get
        Set(value As String)
            Pro.TextTitel = value
            lblText.Text = Pro.TextTitel

            If value <> "" Then
                tlp.RowStyles.Item(0).Height = 12
            Else
                tlp.RowStyles.Item(0).Height = 0
            End If
        End Set
    End Property
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("ستون های فقط خواندنی")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property ReadyOnlyColumns As String
        Get
            Return Pro.ReadyOnlyColumns
        End Get
        Set(value As String)
            Pro.ReadyOnlyColumns = value
        End Set
    End Property
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("راست به چپ استفاده از فارسی")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property RightToLeft_p As Boolean
        Get
            Return Pro.RightToLeft
        End Get
        Set(value As Boolean)
            Pro.RightToLeft = value
            dgv.RightToLeft = IIf(Pro.RightToLeft, 1, 0)
            lblText.RightToLeft = IIf(Pro.RightToLeft, 1, 0)
            tlp.RightToLeft = IIf(Pro.RightToLeft, 1, 0)
            getColumnsWitdh()
        End Set
    End Property
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("ستون کلید اصلی")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property PrimaryKeyColumn As String
        Get
            Return Pro.PrimaryKeyColumn
        End Get
        Set(value As String)
            Pro.PrimaryKeyColumn = value
        End Set
    End Property
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("SQL")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property SelectCommand As String
        Get
            If Pro.SelectCommand = "" Then
                Pro.SelectCommand = "SELECT * FROM " & Pro.TableName
            End If
            Return Pro.SelectCommand
        End Get
        Set(value As String)
            Pro.SelectCommand = value
        End Set
    End Property
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("پسورد دیتابیس")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property PassWord As String
        Get
            Return Pro.PassWord
        End Get
        Set(value As String)
            Pro.PassWord = value
        End Set
    End Property
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("نام دیتابیس همراه مسیر")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property FullNameDataBase As String
        Get
            Return Pro.fullNameDataBase
        End Get
        Set(value As String)
            Pro.fullNameDataBase = value
        End Set
    End Property
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("نام جدول")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property TableName As String
        Get
            Return Pro.TableName
        End Get
        Set(value As String)

            SelectCommand = Replace(SelectCommand, Pro.TableName, value)
            Pro.TableName = value

        End Set
    End Property
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("ستون ها جهت مخفی کردن")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property NonVisibleColumns As String
        Get
            Return Pro.NonVisibleColumns
        End Get
        Set(value As String)
            Pro.NonVisibleColumns = value
        End Set
    End Property
    <CategoryAttribute("_All Setting"), DefaultValueAttribute(""),
    DescriptionAttribute("رشته کانکشن ها به دیتابیس")>
    <Editor(GetType(claShowForm), GetType(UITypeEditor))>
    Public Property Connection_String As String
        Get
            If Pro.ConnectionString = "" Then
                Pro.ConnectionString = gConnectinString
            End If
            Return Pro.ConnectionString
        End Get
        Set(value As String)
            Pro.ConnectionString = value
        End Set
    End Property
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,889 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,211 Reputation points Microsoft External Staff
    2023-06-05T08:54:49.27+00:00

    Hi @Mansour_Dalir ,

    When you modify a property in code via PropertyInfo, the corresponding form file does not display an asterisk (*) to indicate unsaved changes. This is because modifications are made through code, not manually in the designer.

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Mansour_Dalir 2,036 Reputation points
    2023-06-11T04:41:53.42+00:00

    hi .I found a solution for this question with this method. It answers.

        Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    
            'TAB>Home>A>Enter>TAB>Home>Del>Enter
            keybd_event(9, 0, 1, 0)
            keybd_event(9, 0, 2, 0)
            keybd_event(36, 0, 1, 0)
            keybd_event(36, 0, 2, 0)
            keybd_event(65, 0, 1, 0)
            keybd_event(65, 0, 2, 0)
            keybd_event(13, 0, 1, 0)
            keybd_event(13, 0, 2, 0)
            keybd_event(9, 0, 1, 0)
            keybd_event(9, 0, 2, 0)
            keybd_event(36, 0, 1, 0)
            keybd_event(36, 0, 2, 0)
            keybd_event(46, 0, 1, 0)
            keybd_event(46, 0, 2, 0)
            keybd_event(13, 0, 1, 0)
            keybd_event(13, 0, 2, 0)
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.