gammasoft71 / xtd

Free open-source modern C++17 / C++20 framework to create console, GUI (forms like WinForms) and unit test applications and libraries on Microsoft Windows, Apple macOS and Linux.
https://gammasoft71.github.io/xtd
MIT License
735 stars 57 forks source link

[BUG] xtd.forms - combo_box::selected_index(index) and selected::item(item) only work once #200

Closed jimorc closed 1 year ago

jimorc commented 1 year ago

Describe the bug

Here is a small test program. In it, I populate a combo_box when the drop_down event is raised. Note that I clear any items in the combo_box before I populate the list. After populating the list, I select the first one.

The first time I open the combo_box, the item is selected. On all subsequent times, the item is not selected. It does not matter whether I select the item by calling selected_index or selected_item.

#include <xtd/xtd>

using namespace xtd;
using namespace xtd::forms;

class form1 : public form {
  public:
    form1() {
      box_.drop_down += event_handler(*this, &form1::box_drop_down);
      *this << box_;
    }
    void box_drop_down(object& sender, const event_args& e)
    {
      box_.items().clear();
      box_.items().push_back({"Item 1"});
      box_.selected_index(0);
    }
  private:
    combo_box box_;
};

int main()
{
  application::run(form1 {} );
}

To Reproduce

  1. Build and execute the program.
  2. Click to open the combo_box dropdown list. The item is selected.
  3. Close, then reopen the dropdown list. The item is not selected.

Expected behaviour

The item in the dropdown list should always be selected.

Desktop

Additional context

The number of items in the dropdown list does not matter.

Workaround

Select item manually.

gammasoft71 commented 1 year ago

Thanks for your feedback. I'm going to watch ASAP

gammasoft71 commented 1 year ago

I have fixed this problem, can you try if it is correct for you.

jimorc commented 1 year ago

Yes, it is working in the test program.

On 2022-10-21 16:37, Gammasoft wrote:

I have fixed this problem, can you try if it is correct for you.

— Reply to this email directly, view it on GitHub https://github.com/gammasoft71/xtd/issues/200#issuecomment-1287413929, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABET46FBCE33XAL4L4JD4KLWEL5IXANCNFSM6AAAAAARLBJ2NY. You are receiving this because you authored the thread.Message ID: @.***>

-- Jim