Code Monkey home page Code Monkey logo

Comments (2)

RyanWalpole avatar RyanWalpole commented on June 20, 2024

Issue Investigation
Currently the application uses the "Click" event for the listboxes. This fires even when the listbox is clicked on but nothing is selected - hence the current behaviour.

private void InstalledModsList_Click(object sender, EventArgs e)
        {
            AvailableModsList.SelectedItem = null;
            DeleteMod.Enabled = false;
            EnableMod.Enabled = false;
            DisableMod.Enabled = true;
        }

Proposed Solution
Immediately the proposed solution would be to move to the "SelectedValueChanged" event so that it only fires code when the listbox selection changes. This however has the flaw in that the code deselects any item in the opposite list box - which then would fire the SelectedValueChanged again - simply having both buttons be enabled anyway.

from stardew-valley-mod-manager.

RyanWalpole avatar RyanWalpole commented on June 20, 2024

Issue Resolved
The issue has been resolved. I decided not to go with the SelectedValueChanged event as it was causing too many other issues to arise. Instead, I decided to retrieve the SelectedIndex value. When nothing is selected, it returns a value of -1. Therefore I can make an if statement, if value returned is less than 0 (nothing selected), do this.

New code can be found below:

private void InstalledModsList_Click(object sender, EventArgs e)
        {
            if(InstalledModsList.SelectedIndex < 0)
            {
                //AvailableModsList.SelectedItem = null;
                //AvailableModsList.SelectedIndex = -1;
            }
            else
            {
                AvailableModsList.SelectedItem = null;
                AvailableModsList.SelectedIndex = -1;
                DeleteMod.Enabled = false;
                EnableMod.Enabled = false;
                DisableMod.Enabled = true;
            }
        }

        private void AvailableModsList_Click(object sender, EventArgs e)
        {
            if (AvailableModsList.SelectedIndex < 0)
            {
                //InstalledModsList.SelectedItem = null;
                //InstalledModsList.SelectedIndex = -1;
            }
            else
            {
                InstalledModsList.SelectedItem = null;
                InstalledModsList.SelectedIndex = -1;
                DeleteMod.Enabled = true;
                EnableMod.Enabled = true;
                DisableMod.Enabled = false;
            }
        }

Now it will only disable and enable the interactability of the buttons if the listbox is clicked AND the SelectedIndex value is 0 and higher (a valid selection).

from stardew-valley-mod-manager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.