private void ComboBoxWithImg_Load(object sender, EventArgs e)
        {
            comboBox = new MyImgComboBox();
            comboBox.SetBounds(2, 2, 200, 50);
            comboBox.ItemHeight = 50;
            this.Controls.Add(comboBox);
            Image          img       = new Bitmap(this.GetType(), "1.jpg");
            MyComboBoxItem firstItem = new MyComboBoxItem(img, "S***n");

            comboBox.Items.Add(firstItem);
            comboBox.SelectedIndex = 0;
        }
    private void cb1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //get the combobox item
        MyComboBoxItem item = (sender as ComboBox).SelectedItem as MyComboBoxItem;

        //make sure no shinanigans are going on
        if (item == null)
        {
            return;
        }

        //clear out combobox 2
        cb2.Items.Clear();

        //add sub items
        cb2.Items.AddRange(item.SubItems.ToArray());
    }
Exemple #3
0
        public MainWindow()
        {
            InitializeComponent();

            var data = new List <HocSinh> {
                new HocSinh {
                    MSSV = 20172605, Name = "Le Quang Huy"
                },
                new HocSinh {
                    MSSV = 20172538, Name = "Nguyen Thi Hien"
                },
            };

            var sp = new StackPanel
            {
                Background  = Brushes.AliceBlue,
                Orientation = Orientation.Horizontal,
            };
            var mcb = new MyComboBox();

            foreach (var item in data)
            {
                var mcbi = new MyComboBoxItem(item, "Name", "MSSV");
                mcb.Add(mcbi);
            }

            var bt = new Button
            {
                Content = "Submit",
                Width   = 50,
                Height  = 25,
            };

            bt.Click += (s, e) =>
            {
                MessageBox.Show(mcb.SelectedItem.ReturnValue.ToString());
            };

            sp.Children.Add(mcb);
            sp.Children.Add(bt);
            Content = sp;
        }
Exemple #4
0
            public void Add(MyComboBoxItem i)
            {
                i.MouseMove += (s, e) =>
                {
                    i.IsFocus = true;
                    i.BorderItem.Background = Brushes.LightGray;
                };

                i.MouseLeave += (s, e) =>
                {
                    i.IsFocus = false;
                    i.BorderItem.Background = Brushes.White;
                };

                i.MouseLeftButtonDown += (s, e) =>
                {
                    Input.Text   = i.DisplayValue;
                    SelectedItem = i;
                };

                this.KeyDown += (s, e) =>
                {
                    if (e.Key == Key.Enter)
                    {
                        if (i.IsFocus == true)
                        {
                            Input.Text   = i.DisplayValue;
                            SelectedItem = i;
                            Popup.IsOpen = false;
                        }
                    }
                };


                Items.Children.Add(i);
            }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            MyComboBoxItem newItem = new MyComboBoxItem(Image.FromFile(pictureFileName), textBox1.Text);

            comboBox.Items.Add(newItem);
        }