Combobox problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?=

    Combobox problems

    Hi,

    I'm using a combobox in DropDown style. It shows the time in hours for a
    proces. In the drop down list I've put in some values like

    15 min
    30 min
    45 min
    1 h
    2h
    etc...

    When these are selected, they are converted into hours. This number is
    written in the Text property of the cmb_control. I.e. when 45 min is
    selected, I want the combobox to show 0.75. However, It's like the Text
    property is not reacting (or cannot override a selected index). I've tried
    deselect by setting the SelectedIndex property to -1 before writing to the
    Text property of the control, but it does not work either.

    How can I enforce the Text property of the combobox shown after a
    SelectedIndexCh anged event.

    Any idea to resolve this problem?

    Regards Jesper.

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Combobox problems

    Jesper,

    This doesn't resolve your issue, but from a UI standpoint, it's a little
    confusing to have one thing displayed in the drop down list, and then
    another displayed in the box when you select that item. Wouldn't it just be
    easier to have one consistent representation for the value?


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Jesper, Denmark" <JesperDenmark@ discussions.mic rosoft.comwrote in message
    news:E4CCB292-F25F-447A-940A-833494F67A27@mi crosoft.com...
    Hi,
    >
    I'm using a combobox in DropDown style. It shows the time in hours for a
    proces. In the drop down list I've put in some values like
    >
    15 min
    30 min
    45 min
    1 h
    2h
    etc...
    >
    When these are selected, they are converted into hours. This number is
    written in the Text property of the cmb_control. I.e. when 45 min is
    selected, I want the combobox to show 0.75. However, It's like the Text
    property is not reacting (or cannot override a selected index). I've tried
    deselect by setting the SelectedIndex property to -1 before writing to the
    Text property of the control, but it does not work either.
    >
    How can I enforce the Text property of the combobox shown after a
    SelectedIndexCh anged event.
    >
    Any idea to resolve this problem?
    >
    Regards Jesper.
    >

    Comment

    • =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?=

      #3
      Re: Combobox problems

      From a programming point of view yes, but not for my purposes.
      However I just found 5 mins ago an article where another guy had the same
      problem. It was resolved with delegates:

      please have a look at


      (or see snippet below)

      ....and tell me what you think, is it a hack?

      SNIPPET *************** *****
      private delegate void ChangeTextDeleg ete();

      public void ChangeText()
      {
      DataRowView dv = this.comboBox1. SelectedItem as DataRowView;
      this.comboBox1. Text = dv["value"].ToString();
      this.comboBox1. SelectionStart = this.comboBox1. Text.Length;
      }

      void comboBox1_Selec tedIndexChanged (object sender, EventArgs e)
      {
      this.BeginInvok e(new ChangeTextDeleg ete(ChangeText) );
      }
      END SNIPPET *************** ***************

      "Nicholas Paldino [.NET/C# MVP]" wrote:
      Jesper,
      >
      This doesn't resolve your issue, but from a UI standpoint, it's a little
      confusing to have one thing displayed in the drop down list, and then
      another displayed in the box when you select that item. Wouldn't it just be
      easier to have one consistent representation for the value?
      >
      >
      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m
      >
      "Jesper, Denmark" <JesperDenmark@ discussions.mic rosoft.comwrote in message
      news:E4CCB292-F25F-447A-940A-833494F67A27@mi crosoft.com...
      Hi,

      I'm using a combobox in DropDown style. It shows the time in hours for a
      proces. In the drop down list I've put in some values like

      15 min
      30 min
      45 min
      1 h
      2h
      etc...

      When these are selected, they are converted into hours. This number is
      written in the Text property of the cmb_control. I.e. when 45 min is
      selected, I want the combobox to show 0.75. However, It's like the Text
      property is not reacting (or cannot override a selected index). I've tried
      deselect by setting the SelectedIndex property to -1 before writing to the
      Text property of the control, but it does not work either.

      How can I enforce the Text property of the combobox shown after a
      SelectedIndexCh anged event.

      Any idea to resolve this problem?

      Regards Jesper.
      >
      >
      >

      Comment

      • Andrus

        #4
        Re: Combobox problems

        please have a look at
        >

        (or see snippet below)
        >
        ...and tell me what you think, is it a hack?
        I need to create SWF ComboBox which displays multiple properties in
        downdown list but single property in textbox.

        Is it reasonable to use this (BeginInvoke) to create such ComboBox ?

        Andrus.


        Comment

        • Nicholas Paldino [.NET/C# MVP]

          #5
          Re: Combobox problems

          Jesper,

          The comment wasn't about the programming point of view. From a UI
          perspective, it just doesn't make sense.

          Regardless, the reason why this works is that it calls BeginInvoke.
          BeginInvoke will send the windows message to call the delegate, but not wait
          for it to be processed, which means that it returns immediately, and then
          will be processed sometime after the current event handler exits.

          It is a hack, IMO, but without fundamentally changing the combobox, it's
          probably your best shot right now.

          You should be aware that it's not guaranteed that the delegate will be
          called immediately after the method that calls BeginInvoke exists. It's
          completely possible that there will be other windows messages that are
          placed in the queue to be processed beforehand, and those have to be
          processed before the delegate is executed.


          --
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard. caspershouse.co m

          "Jesper, Denmark" <JesperDenmark@ discussions.mic rosoft.comwrote in message
          news:D9B284D6-A514-42F8-A852-7D3E670FCF50@mi crosoft.com...
          From a programming point of view yes, but not for my purposes.
          However I just found 5 mins ago an article where another guy had the same
          problem. It was resolved with delegates:
          >
          please have a look at
          >

          (or see snippet below)
          >
          ...and tell me what you think, is it a hack?
          >
          SNIPPET *************** *****
          private delegate void ChangeTextDeleg ete();
          >
          public void ChangeText()
          {
          DataRowView dv = this.comboBox1. SelectedItem as DataRowView;
          this.comboBox1. Text = dv["value"].ToString();
          this.comboBox1. SelectionStart = this.comboBox1. Text.Length;
          }
          >
          void comboBox1_Selec tedIndexChanged (object sender, EventArgs e)
          {
          this.BeginInvok e(new ChangeTextDeleg ete(ChangeText) );
          }
          END SNIPPET *************** ***************
          >
          "Nicholas Paldino [.NET/C# MVP]" wrote:
          >
          >Jesper,
          >>
          > This doesn't resolve your issue, but from a UI standpoint, it's a
          >little
          >confusing to have one thing displayed in the drop down list, and then
          >another displayed in the box when you select that item. Wouldn't it just
          >be
          >easier to have one consistent representation for the value?
          >>
          >>
          >--
          > - Nicholas Paldino [.NET/C# MVP]
          > - mvp@spam.guard. caspershouse.co m
          >>
          >"Jesper, Denmark" <JesperDenmark@ discussions.mic rosoft.comwrote in
          >message
          >news:E4CCB29 2-F25F-447A-940A-833494F67A27@mi crosoft.com...
          Hi,
          >
          I'm using a combobox in DropDown style. It shows the time in hours for
          a
          proces. In the drop down list I've put in some values like
          >
          15 min
          30 min
          45 min
          1 h
          2h
          etc...
          >
          When these are selected, they are converted into hours. This number is
          written in the Text property of the cmb_control. I.e. when 45 min is
          selected, I want the combobox to show 0.75. However, It's like the Text
          property is not reacting (or cannot override a selected index). I've
          tried
          deselect by setting the SelectedIndex property to -1 before writing to
          the
          Text property of the control, but it does not work either.
          >
          How can I enforce the Text property of the combobox shown after a
          SelectedIndexCh anged event.
          >
          Any idea to resolve this problem?
          >
          Regards Jesper.
          >
          >>
          >>
          >>

          Comment

          • Nicholas Paldino [.NET/C# MVP]

            #6
            Re: Combobox problems

            Andrus,

            No, this will not help you. You basically need to handle the repainting
            of the entire drop down yourself, so you have to override the combobox
            behaivor to do that.


            --
            - Nicholas Paldino [.NET/C# MVP]
            - mvp@spam.guard. caspershouse.co m

            "Andrus" <kobruleht2@hot .eewrote in message
            news:erJdPqnaIH A.208@TK2MSFTNG P02.phx.gbl...
            >please have a look at
            >>
            >https://forums.microsoft.com/MSDN/Sh...57193&SiteID=1
            >(or see snippet below)
            >>
            >...and tell me what you think, is it a hack?
            >
            I need to create SWF ComboBox which displays multiple properties in
            downdown list but single property in textbox.
            >
            Is it reasonable to use this (BeginInvoke) to create such ComboBox ?
            >
            Andrus.
            >
            >

            Comment

            Working...