已使用html方式处理简单很多
谢谢你的回答 可惜英文难以看懂 并不能解决我的问题
public partial class Form1 : Form
{
Headers header = new Headers();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
header.item = new List<Items>();
Items item = new Items();
item.key = "湖南";
item.values = new List<string>() { "长沙", "张家界", "吉首" };
Items item2 = new Items();
item2.key = "湖北";
item2.values = new List<string>() { "武汉", "黄冈" };
Items item3 = new Items();
item3.key = "江西";
item3.values = new List<string>() { "南昌", "赣州", "新余" };
header.item.Add(item);
header.item.Add(item2);
header.item.Add(item3);
foreach (var itemKey in header.item)
{
comboBox1.Items.Add(itemKey.key);
}
comboBox1.SelectedIndex = 0;
foreach (var itemKey in header.item)
{
if (comboBox1.Text == itemKey.key)
{
foreach (var itemValues in itemKey.values)
{
comboBox2.Items.Add(itemValues);
}
}
}
comboBox2.SelectedIndex = 0;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.Items.Clear();
foreach (var itemKey in header.item)
{
if (comboBox1.Text == itemKey.key)
{
foreach (var itemValues in itemKey.values)
{
comboBox2.Items.Add(itemValues);
}
}
}
comboBox2.SelectedIndex = 0;
}
}
不知道是不是你想要的效果
如果能把他放到DataGridView里面就完美了
@阿鱿爱吃草莓: 什么意思 不是很明白
@小小怪l: 貌似挺麻烦的(⊙o⊙)…
我这个用DEV控件写的,与DataGridView不一样
private void gridViewX_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e)
{
DevExpress.XtraGrid.Views.Grid.GridView gv = sender as DevExpress.XtraGrid.Views.Grid.GridView;
if (e.Column.FieldName != "参数值")
{
return;
}
string fieldName = gv.GetRowCellValue(e.RowHandle, gv.Columns["类型"]).ToString();
if (fieldName != "")
{
RepositoryItemGridLookUpEdit luk = new RepositoryItemGridLookUpEdit();
luk.DisplayMember = "描述";
luk.ValueMember = "值";
string enumName = gv.GetRowCellValue(e.RowHandle, gv.Columns["类型"]).ToString();
IList<EnumTable> list = PublicClass.EnumDatatable().Where(c => c.名称 == enumName).ToList();
luk.DataSource = list;
luk.View.DataSourceChanged += View_DataSourceChanged;
e.RepositoryItem = luk;
}
else
{
RepositoryItemTextEdit txt = new RepositoryItemTextEdit();
txt.NullText = gv.GetRowCellValue(e.RowHandle, gv.Columns["参数值"]).ToString();
e.RepositoryItem = txt;
}
}
是这个效果 这个控件在哪找的 要钱吗
每一行都有自己不同的combox