Set Focus To Specific Property In Property Grid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Derek Hart

    Set Focus To Specific Property In Property Grid

    I can set focus to my property grid by using propgrid.Focus - but how can I
    set the default property that is always first? Or just set focus to the
    default property? Can this be done?


  • kimiraikkonen

    #2
    Re: Set Focus To Specific Property In Property Grid

    On Sep 27, 11:40 pm, "Derek Hart" <derekmh...@yah oo.comwrote:
    I can set focus to my property grid by using propgrid.Focus - but how canI
    set the default property that is always first? Or just set focus to the
    default property? Can this be done?
    Hi Derek,

    To select(or focus) a pre-defined property in a PropertyGrid control
    programmaticall y, you can use loop through GridItems and check "label"
    to determine which item to be selected:

    '------Begin-----
    Dim GridItem As GridItem = PropertyGrid1.S electedGridItem
    Dim pGridItem As GridItem = GridItem.Parent
    For Each egi As GridItem In pGridItem.GridI tems
    If egi.Label = "property_label _here" Then
    PropertyGrid1.F ocus()
    egi.Select()
    End If
    Next
    '------End-------


    Hope this helps,

    Onur Güzel

    Comment

    • Derek Hart

      #3
      Re: Set Focus To Specific Property In Property Grid

      Thank you for the answer. Just need to add one thing to it. I am running
      this code on the keydown event for a textbox control. It sets focus to the
      grid properly now. But I need to trap the keystroke that was hit and fill it
      in as the first character in the property, just like how Visual Studio works
      when you are on a control and hit the first keyboard character and it starts
      typing in the default property for that control. Is this possible?


      "kimiraikko nen" <kimiraikkonen8 5@gmail.comwrot e in message
      news:d0081a3d-c555-4854-a226-dfdfaa56b500@2g 2000hsn.googleg roups.com...
      On Sep 27, 11:40 pm, "Derek Hart" <derekmh...@yah oo.comwrote:
      I can set focus to my property grid by using propgrid.Focus - but how can
      I
      set the default property that is always first? Or just set focus to the
      default property? Can this be done?
      Hi Derek,

      To select(or focus) a pre-defined property in a PropertyGrid control
      programmaticall y, you can use loop through GridItems and check "label"
      to determine which item to be selected:

      '------Begin-----
      Dim GridItem As GridItem = PropertyGrid1.S electedGridItem
      Dim pGridItem As GridItem = GridItem.Parent
      For Each egi As GridItem In pGridItem.GridI tems
      If egi.Label = "property_label _here" Then
      PropertyGrid1.F ocus()
      egi.Select()
      End If
      Next
      '------End-------


      Hope this helps,

      Onur Güzel


      Comment

      • kimiraikkonen

        #4
        Re: Set Focus To Specific Property In Property Grid

        On Sep 28, 8:33 pm, "Derek Hart" <derekmh...@yah oo.comwrote:
        Thank you for the answer. Just need to add one thing to it. I am running
        this code on the keydown event for a textbox control. It sets focus to the
        grid properly now. But I need to trap the keystroke that was hit and fillit
        in as the first character in the property, just like how Visual Studio works
        when you are on a control and hit the first keyboard character and it starts
        typing in the default property for that control. Is this possible?
        >
        "kimiraikko nen" <kimiraikkone.. .@gmail.comwrot e in message
        >
        news:d0081a3d-c555-4854-a226-dfdfaa56b500@2g 2000hsn.googleg roups.com...
        On Sep 27, 11:40 pm, "Derek Hart" <derekmh...@yah oo.comwrote:
        >
        I can set focus to my property grid by using propgrid.Focus - but how can
        I
        set the default property that is always first? Or just set focus to the
        default property? Can this be done?
        >
        Hi Derek,
        >
        To select(or focus) a pre-defined property in a PropertyGrid control
        programmaticall y, you can use loop through GridItems and check "label"
        to determine which item to be selected:
        >
        '------Begin-----
        Dim GridItem As GridItem = PropertyGrid1.S electedGridItem
        Dim pGridItem As GridItem = GridItem.Parent
        For Each egi As GridItem In pGridItem.GridI tems
        If egi.Label = "property_label _here" Then
        PropertyGrid1.F ocus()
        egi.Select()
        End If
        Next
        '------End-------
        >
        Hope this helps,
        >
        Onur Güzel
        As far as i understand (i couldn't guess well maybe), you're wanting
        something like IntelliSense or setting the value of a property within
        textbox, and setting PropertyGrid item's value outside PropertyGrid
        control is not possible, because "Value" property is ReadOnly.

        Or, my another guess that if you want to highlight a property grid
        item which is inside PropertyGrid control while initial key matches
        with the text in textbox you can use that:

        '--------------Begin-------------
        Private Sub TextBox1_KeyDow n(ByVal sender As System.Object, _
        ByVal e As System.Windows. Forms.KeyEventA rgs) _
        Handles TextBox1.KeyDow n

        Dim GridItem As GridItem = _
        PropertyGrid1.S electedGridItem
        Dim pGridItem As GridItem = _
        GridItem.Parent
        For Each egi As GridItem In _
        pGridItem.GridI tems
        If egi.Label.Start sWith(e.KeyData .ToString) Then
        PropertyGrid1.F ocus()
        egi.Select()
        End If
        Next

        End Sub
        '--------End----------

        HTH,

        Onur Güzel

        Comment

        • Derek Hart

          #5
          Re: Set Focus To Specific Property In Property Grid

          Not quite. When I am in Visual Studio designing a form, and I highlight a
          text box, when I then hit a letter, such as "T", it moves the cursor to the
          property grid into the text property and enters "T" - then then user can
          type the rest of the text in this property. Make sense?

          "kimiraikko nen" <kimiraikkonen8 5@gmail.comwrot e in message
          news:fe617152-5304-485f-86d6-7ec85323e170@y7 1g2000hsa.googl egroups.com...
          On Sep 28, 8:33 pm, "Derek Hart" <derekmh...@yah oo.comwrote:
          Thank you for the answer. Just need to add one thing to it. I am running
          this code on the keydown event for a textbox control. It sets focus to the
          grid properly now. But I need to trap the keystroke that was hit and fill
          it
          in as the first character in the property, just like how Visual Studio
          works
          when you are on a control and hit the first keyboard character and it
          starts
          typing in the default property for that control. Is this possible?
          >
          "kimiraikko nen" <kimiraikkone.. .@gmail.comwrot e in message
          >
          news:d0081a3d-c555-4854-a226-dfdfaa56b500@2g 2000hsn.googleg roups.com...
          On Sep 27, 11:40 pm, "Derek Hart" <derekmh...@yah oo.comwrote:
          >
          I can set focus to my property grid by using propgrid.Focus - but how
          can
          I
          set the default property that is always first? Or just set focus to the
          default property? Can this be done?
          >
          Hi Derek,
          >
          To select(or focus) a pre-defined property in a PropertyGrid control
          programmaticall y, you can use loop through GridItems and check "label"
          to determine which item to be selected:
          >
          '------Begin-----
          Dim GridItem As GridItem = PropertyGrid1.S electedGridItem
          Dim pGridItem As GridItem = GridItem.Parent
          For Each egi As GridItem In pGridItem.GridI tems
          If egi.Label = "property_label _here" Then
          PropertyGrid1.F ocus()
          egi.Select()
          End If
          Next
          '------End-------
          >
          Hope this helps,
          >
          Onur Güzel
          As far as i understand (i couldn't guess well maybe), you're wanting
          something like IntelliSense or setting the value of a property within
          textbox, and setting PropertyGrid item's value outside PropertyGrid
          control is not possible, because "Value" property is ReadOnly.

          Or, my another guess that if you want to highlight a property grid
          item which is inside PropertyGrid control while initial key matches
          with the text in textbox you can use that:

          '--------------Begin-------------
          Private Sub TextBox1_KeyDow n(ByVal sender As System.Object, _
          ByVal e As System.Windows. Forms.KeyEventA rgs) _
          Handles TextBox1.KeyDow n

          Dim GridItem As GridItem = _
          PropertyGrid1.S electedGridItem
          Dim pGridItem As GridItem = _
          GridItem.Parent
          For Each egi As GridItem In _
          pGridItem.GridI tems
          If egi.Label.Start sWith(e.KeyData .ToString) Then
          PropertyGrid1.F ocus()
          egi.Select()
          End If
          Next

          End Sub
          '--------End----------

          HTH,

          Onur Güzel


          Comment

          • kimiraikkonen

            #6
            Re: Set Focus To Specific Property In Property Grid

            On Sep 29, 1:17 am, "Derek Hart" <derekmh...@yah oo.comwrote:
            Not quite. When I am in Visual Studio designing a form, and I highlight a
            text box, when I then hit a letter, such as "T", it moves the cursor to the
            property grid into the text property and enters "T" - then then user can
            type the rest of the text in this property.  Make sense?
            >
            "kimiraikko nen" <kimiraikkone.. .@gmail.comwrot e in message
            >
            news:fe617152-5304-485f-86d6-7ec85323e170@y7 1g2000hsa.googl egroups.com...
            On Sep 28, 8:33 pm, "Derek Hart" <derekmh...@yah oo.comwrote:
            >
            >
            >
            Thank you for the answer. Just need to add one thing to it. I am running
            this code on the keydown event for a textbox control. It sets focus to the
            grid properly now. But I need to trap the keystroke that was hit and fill
            it
            in as the first character in the property, just like how Visual Studio
            works
            when you are on a control and hit the first keyboard character and it
            starts
            typing in the default property for that control. Is this possible?
            >
            "kimiraikko nen" <kimiraikkone.. .@gmail.comwrot e in message
            >
            news:d0081a3d-c555-4854-a226-dfdfaa56b500@2g 2000hsn.googleg roups.com...
            On Sep 27, 11:40 pm, "Derek Hart" <derekmh...@yah oo.comwrote:
            >
            I can set focus to my property grid by using propgrid.Focus - but how
            can
            I
            set the default property that is always first? Or just set focus to the
            default property? Can this be done?
            >
            Hi Derek,
            >
            To select(or focus) a pre-defined property in a PropertyGrid control
            programmaticall y, you can use loop through GridItems and check "label"
            to determine which item to be selected:
            >
            '------Begin-----
            Dim GridItem As GridItem = PropertyGrid1.S electedGridItem
            Dim pGridItem As GridItem = GridItem.Parent
            For Each egi As GridItem In pGridItem.GridI tems
            If egi.Label = "property_label _here" Then
            PropertyGrid1.F ocus()
            egi.Select()
            End If
            Next
            '------End-------
            >
            Hope this helps,
            >
            Onur Güzel
            >
            As far as i understand (i couldn't guess well maybe), you're wanting
            something like IntelliSense or setting the value of a property within
            textbox, and setting PropertyGrid item's value outside PropertyGrid
            control is not possible, because "Value" property is ReadOnly.
            >
            Or, my another guess that if you want to highlight a property grid
            item which is inside PropertyGrid control while initial key matches
            with the text in textbox you can use that:
            >
            '--------------Begin-------------
            Private Sub TextBox1_KeyDow n(ByVal sender As System.Object, _
            ByVal e As System.Windows. Forms.KeyEventA rgs) _
            Handles TextBox1.KeyDow n
            >
            Dim GridItem As GridItem = _
            PropertyGrid1.S electedGridItem
            Dim pGridItem As GridItem = _
            GridItem.Parent
            For Each egi As GridItem In _
            pGridItem.GridI tems
            If egi.Label.Start sWith(e.KeyData .ToString) Then
            PropertyGrid1.F ocus()
            egi.Select()
            End If
            Next
            >
            End Sub
            '--------End----------
            >
            HTH,
            >
            Onur Güzel
            Now got it what you desribe in VS. But couldn't associate your aim
            with a textbox and typing in a defaul property of a propertygrid
            control. For example, you can make a property default by using
            "DefaultPropert yAttribute" in your class, for example you can design
            your class whose default property is "Title" as follows:

            <DefaultPropert yAttribute("Tit le")_
            Public Class SampleProperty

            Private _Title As String

            <CategoryAttrib ute("Applicatio n"), _
            Browsable(True) , _
            [ReadOnly](False), _
            BindableAttribu te(False), _
            DefaultValueAtt ribute(""), _
            DesignOnly(Fals e), _
            DescriptionAttr ibute("Enter Title for the application")_
            Public Property Title() As String
            Get
            Return _Title
            End Get
            Set(ByVal Value As String)
            _Title = Value
            End Set
            End Property

            Now, when you associate that class with PropertyGrid using:
            "PropertyGrid1. SelectedObject = New SampleProperty" preferably in
            form1_load event, "Title" property is pre-selected in gray and when
            you type in a textbox using the code above, it gets focus in blue and
            starts to type the value of that property.

            Sorry, if i got wrong,

            Hope this helps,

            Onur Güzel

            Comment

            • Derek Hart

              #7
              Re: Set Focus To Specific Property In Property Grid

              Not sure I understand how this will solve the problem. In Visual Studio, if
              I design a text box, then highlight it and hit a keyboard character, it will
              set focus to the property grid, and enter that character in the "text"
              property waiting for more input. Can I recreate this somehow?


              "kimiraikko nen" <kimiraikkonen8 5@gmail.comwrot e in message
              news:1a2c3eeb-464a-4bb1-ba21-186ae472b3e0@f3 6g2000hsa.googl egroups.com...
              On Sep 29, 1:17 am, "Derek Hart" <derekmh...@yah oo.comwrote:
              Not quite. When I am in Visual Studio designing a form, and I highlight a
              text box, when I then hit a letter, such as "T", it moves the cursor to
              the
              property grid into the text property and enters "T" - then then user can
              type the rest of the text in this property. Make sense?
              >
              "kimiraikko nen" <kimiraikkone.. .@gmail.comwrot e in message
              >
              news:fe617152-5304-485f-86d6-7ec85323e170@y7 1g2000hsa.googl egroups.com...
              On Sep 28, 8:33 pm, "Derek Hart" <derekmh...@yah oo.comwrote:
              >
              >
              >
              Thank you for the answer. Just need to add one thing to it. I am running
              this code on the keydown event for a textbox control. It sets focus to
              the
              grid properly now. But I need to trap the keystroke that was hit and
              fill
              it
              in as the first character in the property, just like how Visual Studio
              works
              when you are on a control and hit the first keyboard character and it
              starts
              typing in the default property for that control. Is this possible?
              >
              "kimiraikko nen" <kimiraikkone.. .@gmail.comwrot e in message
              >
              news:d0081a3d-c555-4854-a226-dfdfaa56b500@2g 2000hsn.googleg roups.com...
              On Sep 27, 11:40 pm, "Derek Hart" <derekmh...@yah oo.comwrote:
              >
              I can set focus to my property grid by using propgrid.Focus - but how
              can
              I
              set the default property that is always first? Or just set focus to
              the
              default property? Can this be done?
              >
              Hi Derek,
              >
              To select(or focus) a pre-defined property in a PropertyGrid control
              programmaticall y, you can use loop through GridItems and check "label"
              to determine which item to be selected:
              >
              '------Begin-----
              Dim GridItem As GridItem = PropertyGrid1.S electedGridItem
              Dim pGridItem As GridItem = GridItem.Parent
              For Each egi As GridItem In pGridItem.GridI tems
              If egi.Label = "property_label _here" Then
              PropertyGrid1.F ocus()
              egi.Select()
              End If
              Next
              '------End-------
              >
              Hope this helps,
              >
              Onur Güzel
              >
              As far as i understand (i couldn't guess well maybe), you're wanting
              something like IntelliSense or setting the value of a property within
              textbox, and setting PropertyGrid item's value outside PropertyGrid
              control is not possible, because "Value" property is ReadOnly.
              >
              Or, my another guess that if you want to highlight a property grid
              item which is inside PropertyGrid control while initial key matches
              with the text in textbox you can use that:
              >
              '--------------Begin-------------
              Private Sub TextBox1_KeyDow n(ByVal sender As System.Object, _
              ByVal e As System.Windows. Forms.KeyEventA rgs) _
              Handles TextBox1.KeyDow n
              >
              Dim GridItem As GridItem = _
              PropertyGrid1.S electedGridItem
              Dim pGridItem As GridItem = _
              GridItem.Parent
              For Each egi As GridItem In _
              pGridItem.GridI tems
              If egi.Label.Start sWith(e.KeyData .ToString) Then
              PropertyGrid1.F ocus()
              egi.Select()
              End If
              Next
              >
              End Sub
              '--------End----------
              >
              HTH,
              >
              Onur Güzel
              Now got it what you desribe in VS. But couldn't associate your aim
              with a textbox and typing in a defaul property of a propertygrid
              control. For example, you can make a property default by using
              "DefaultPropert yAttribute" in your class, for example you can design
              your class whose default property is "Title" as follows:

              <DefaultPropert yAttribute("Tit le")_
              Public Class SampleProperty

              Private _Title As String

              <CategoryAttrib ute("Applicatio n"), _
              Browsable(True) , _
              [ReadOnly](False), _
              BindableAttribu te(False), _
              DefaultValueAtt ribute(""), _
              DesignOnly(Fals e), _
              DescriptionAttr ibute("Enter Title for the application")_
              Public Property Title() As String
              Get
              Return _Title
              End Get
              Set(ByVal Value As String)
              _Title = Value
              End Set
              End Property

              Now, when you associate that class with PropertyGrid using:
              "PropertyGrid1. SelectedObject = New SampleProperty" preferably in
              form1_load event, "Title" property is pre-selected in gray and when
              you type in a textbox using the code above, it gets focus in blue and
              starts to type the value of that property.

              Sorry, if i got wrong,

              Hope this helps,

              Onur Güzel


              Comment

              • Jeff Johnson

                #8
                Re: Set Focus To Specific Property In Property Grid

                "Derek Hart" <derekmhart@yah oo.comwrote in message
                news:eAzNqojIJH A.3932@TK2MSFTN GP03.phx.gbl...
                Not sure I understand how this will solve the problem. In Visual Studio,
                if I design a text box, then highlight it and hit a keyboard character, it
                will set focus to the property grid, and enter that character in the
                "text" property waiting for more input. Can I recreate this somehow?
                Remember that the PropertyGrid has an object assigned to it that serves as
                the source of the data it displays. I think what you need to do is alter
                that object so that your desired property now contains the character that
                was typed and then set your focus to the PropertyGrid and the property.


                Comment

                • =?Utf-8?B?YXRhbGFudGE=?=

                  #9
                  Re: Set Focus To Specific Property In Property Grid

                  Sounds like you want to use a macro in VS.

                  "Derek Hart" wrote:
                  Not sure I understand how this will solve the problem. In Visual Studio, if
                  I design a text box, then highlight it and hit a keyboard character, it will
                  set focus to the property grid, and enter that character in the "text"
                  property waiting for more input. Can I recreate this somehow?

                  Comment

                  • Derek Hart

                    #10
                    Re: Set Focus To Specific Property In Property Grid

                    Thanks for the different information. Just can't get it working. If I have
                    a textbox highlighted (remember, I am in runtime mode with custom code that
                    draws a rectangle around the textbox), then I hit a keystroke, it does set
                    focus to the property grid, and sets focus to the property.

                    Now I tried this code:
                    CType(propGrid. SelectedObject, PropertiesLabel ).LabelName =
                    e.KeyData.ToStr ing
                    propGrid.Refres h

                    So now when I hit a keystroke, it does fill in the first character into the
                    grid. But here is the tricky part. It does not open the property up for
                    editing. It sets focus to the property. Now the user hits another keystroke
                    and it types over the first one. Is is possible after the Refresh is done,
                    to open up the property for editing, and be in the second character
                    position?



                    "atalanta" <atalanta@discu ssions.microsof t.comwrote in message
                    news:9C94AA0A-009D-4CEB-A7AC-B70CB67C8BC3@mi crosoft.com...
                    Sounds like you want to use a macro in VS.
                    >
                    "Derek Hart" wrote:
                    >
                    >Not sure I understand how this will solve the problem. In Visual Studio,
                    >if
                    >I design a text box, then highlight it and hit a keyboard character, it
                    >will
                    >set focus to the property grid, and enter that character in the "text"
                    >property waiting for more input. Can I recreate this somehow?
                    >

                    Comment

                    • Jeff Johnson

                      #11
                      Re: Set Focus To Specific Property In Property Grid

                      "Derek Hart" <derekmhart@yah oo.comwrote in message
                      news:O9cwS3jJJH A.2444@TK2MSFTN GP06.phx.gbl...
                      Thanks for the different information. Just can't get it working. If I
                      have a textbox highlighted (remember, I am in runtime mode with custom
                      code that draws a rectangle around the textbox), then I hit a keystroke,
                      it does set focus to the property grid, and sets focus to the property.
                      >
                      Now I tried this code:
                      CType(propGrid. SelectedObject, PropertiesLabel ).LabelName =
                      e.KeyData.ToStr ing
                      propGrid.Refres h
                      >
                      So now when I hit a keystroke, it does fill in the first character into
                      the grid. But here is the tricky part. It does not open the property up
                      for editing. It sets focus to the property. Now the user hits another
                      keystroke and it types over the first one. Is is possible after the
                      Refresh is done, to open up the property for editing, and be in the second
                      character position?
                      At this point you might have to dig into P/Invoke and just send a keystroke
                      to the property grid with the key_event() API function. If you look at the
                      PropertyGrid class in Reflector you find that there's a bunch of internal
                      and private stuff supporting its functionality, and I doubt you'll be able
                      to access them through the Framework. (Maybe if you derive from the grid?
                      But I doubt it....)


                      Comment

                      Working...