Form1.cs
资源名称:ComboBox.rar [点击查看]
上传用户:eleven0727
上传日期:2022-04-14
资源大小:271k
文件大小:1k
源码类别:
组合框控件
开发平台:
C#
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace TreeComboBoxTest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- this.treeComboBox1.AfterExpand += new TreeViewEventHandler(treeComboBox1_AfterExpand);
- this.treeComboBox1.AfterCollapse += new TreeViewEventHandler(treeComboBox1_AfterCollapse);
- //为下拉列表添加节点
- for (int i = 0; i < 4; i++)
- {
- this.treeComboBox1.Nodes.Add("key" + i, "Depart" + i, 0, 0);
- for (int j = 0; j < i+1; j++)
- {
- this.treeComboBox1.Nodes[i].Nodes.Add("key_child" + i+j, "User" + i+j, 2, 2);
- }
- }
- }
- void treeComboBox1_AfterCollapse(object sender, TreeViewEventArgs e)
- {
- if (e.Node.ImageIndex == 1)
- e.Node.ImageIndex = e.Node.SelectedImageIndex = 0;
- }
- void treeComboBox1_AfterExpand(object sender, TreeViewEventArgs e)
- {
- if (e.Node.ImageIndex == 0)
- e.Node.ImageIndex = e.Node.SelectedImageIndex = 1;
- }
- }
- }