I want to add ComboBox inside ListView on mouse double click event.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanjeev89cs
    New Member
    • Apr 2013
    • 1

    I want to add ComboBox inside ListView on mouse double click event.

    I want to add ComboBox inside ListView on mouse double click event. On each double click, a new ComboBox should be added on the next row.

    I tried it with the code below, but its not working.

    Code:
     private void form_DblClick(object sender, form_DblClickEvent e)
     {
          ComboBox c;
          this.Controls.Add(c = new ComboBox());
          c.Items.Add("Input");
          c.Items.Add("Delay");
          c.Items.Add("Message");
          c.Items.Add("comment");
          listView1.Controls.Add(c);
     }
    actually i want to add combobox will all of the above elements in one combobox..when i double click it again..in next line another combobox will be added with all elements...
    can any one help me in solving this problem..
    Last edited by Rabbit; Apr 9 '13, 06:19 AM. Reason: Please use code tags when posting code.
  • vijay6
    New Member
    • Mar 2010
    • 158

    #2
    Hey sanjeev89cs, you forgot to specify the location of combobox, so that by default all comboboxes uses same position. That's why you're seeing only one combobox at runtime even though you added more than one combobox.

    Mouse double click event on what? Form or ListView or something else? Try this code, i wrote it on mouse double click on Form.

    Code:
    using System;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            ListView listview1;
            int x, y;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                this.MouseDoubleClick += Form1_MouseDoubleClick;
    
                x = y = 0;
    
                listview1 = new ListView();
                listview1.Location = new System.Drawing.Point(12, 12);
                Controls.Add(listview1);
            }
    
            void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                ComboBox cb = new ComboBox();
                cb.Items.Add("Input");
                cb.Items.Add("Delay");
                cb.Items.Add("Message");
                cb.Items.Add("comment");
                cb.Location = new System.Drawing.Point(x, y);
                x = cb.Location.X;
                y = cb.Location.Y + cb.Height;
                listview1.Controls.Add(cb);
            }
        }
    }

    Comment

    Working...