Home > Software engineering >  is it possible to add elements like panel to a listbox, listview or other list with .items value usi
is it possible to add elements like panel to a listbox, listview or other list with .items value usi

Time:08-09

is it possible to add elements like panel to a listbox, listview or other list with .items?

I want to create panels with other elements like labels, checkbox, buttons,.. on a panel. The panel should then be in a list so that I can check it for example: checkbox (which is on the panel) and is active in the list is showing, the other elements should be hidden in the list. If a panel is between 2 panels, it should move upwards so that there is no space in between. If I then only display the panels of the non-activated elements, the hidden ones should be displayed again and the displayed ones should be hidden.

I would like to control this display using button event,

  • show everything,
  • only activated and
  • only deactivated.

With another button I would like to be able to bring a panel to the top position if it was declared as a favorite. if the favorite is removed again it should go back to where it was before.

In addition, I would then like to create a search mask that only displays the elements that match the search string when entered.

The only way I found is with listbox1.Controls.Add(panel1); for it to appear. Unfortunately it doesn't work with listbox1.Items. :( So I don't have a selectedItem either....

Here is my code that I have so far:

    private void Reload_Click(object sender, EventArgs e)
    {
        Panel panel1 = new Panel();
        panel1.Size = new Size (250, 35);
        panel1.BackColor = Color.Red;
        panel1.ForeColor = Color.Green;
        panelxy.Dock = DockStyle.Top;

        Panel panel2 = new Panel();
        panel2.Size = new Size(250, 35);
        panel2.BackColor = Color.Blue;
        panel2.ForeColor = Color.Green;
        panel2.Dock = DockStyle.Top;

        listBox1.Controls.Add(panel1);
        listBox1.Controls.Add(panel2);

        Button btn_1 = new Button();
        btn_1 .Size = new Size(200, 30);
        btn_1 .Location = new Point(5, 2);
        btn_1 .ForeColor = Color.Blue;
        btn_1 .BackColor = Color.Yellow;
        btn_1 .Font = new Font("Sitka Text", 15F, (FontStyle)(FontStyle.Bold | FontStyle.Italic), GraphicsUnit.Point, (byte) 0);
        btn_1 .Text = "testbutton";
        panel1.Controls.Add(btn_1 );
    }

And here a Picture to show that:

listbox_elements

I hope someone can help me here. :) thanks and BR

Cusy

CodePudding user response:

Super thank you!

I just found out that it is possible to realize the required with a TableLayoutPanel. :)

Since I already have about 7000 lines of code, I don't want to convert it to WPF. ;) i think the Answer from "Jimi" with FlowLayoutPanel are also a Solution. :) Thanks

BR Cusy

  • Related