반응형
  
public class ListViewWithComboBox : ListView
        {
            //Field
            ComboBox _comboBox;
            ListViewItem.ListViewSubItem item;

            //properties
            public ComboBox ComBoBox
            {
                get { return _comboBox; }
                set { _comboBox = value; }
            }

            //Constructor
            public ListViewWithComboBox()
                : base()
            {
                ComBoBox = new ComboBox();

                //콤보박스에 값을 셋팅해준다


                ComBoBox.LostFocus += new EventHandler(ComBoBox_LostFocus);
                ComBoBox.SelectedValueChanged += new EventHandler(ComBoBox_SelectedValueChanged);
                
            }

            //public Method
            public void showComboBox()
            {

                 item =  this.SelectedItems[0].SubItems[1];
                _comboBox.Location = item.Bounds.Location;
                _comboBox.Size = item.Bounds.Size;

                _comboBox.SelectedValueChanged -= new EventHandler(ComBoBox_SelectedValueChanged);
                _comboBox.Text = item.Text;
                _comboBox.SelectedValueChanged += new EventHandler(ComBoBox_SelectedValueChanged);
                this.Controls.Add(_comboBox);
                _comboBox.Focus();
            }

            //Event
            void ComBoBox_SelectedValueChanged(object sender, EventArgs e)
            {
                ComboBox combobox = sender as ComboBox;

                //ListView의 Item에 값을 셋팅한다.



                item.Text =  combobox.SelectedItem.ToString();
                 this.Controls.Remove(ComBoBox);
            }

            void ComBoBox_LostFocus(object sender, EventArgs e)
            {
                this.Controls.Remove(_comboBox);
            }


        }

+ Recent posts