2010-10-19 83 views
0

我认为我的问题是有区分性的,或者作为微软在数据网格文档中的问题是,如何让组合框列显示基于数据的子集在不同的组合框列的值?在基于另一个组合框的数据网格中过滤组合框vb.net

我有一个DS填充3个表格,客户,订单,OrderDetails。 订单详细信息位于带有两个组合框列的DataGridView中,1是位置,1是产品。两者都来自单独的查找数据集。

我想要的是当用户选择位置组合时,产品组合应过滤到其可用的位置。产品与位置相关的位置ID

这是从文档的解决方案,但它dosent工作对我来说。

private void Form1_Load(object sender, EventArgs e) 

{ this.territoriesTableAdapter.Fill(this.northwindDataSet.Territories); this.regionTableAdapter.Fill(this.northwindDataSet.Region);

// Setup BindingSource for filtered view. 
filteredTerritoriesBS = new BindingSource(); 
DataView dv = new DataView(northwindDataSet.Tables["Territories"]); 
filteredTerritoriesBS.DataSource = dv; 

}

私人无效dataGridView1_CellBeginEdit(对象发件人, DataGridViewCellCancelEventArgs E) { 如果(e.ColumnIndex == territoryComboBoxColumn.Index) { //设置组合框单元的数据源的过滤BindingSource DataGridViewComboBoxCell dgcb =(DataGridViewComboBoxCell)dataGridView1 [e.ColumnIndex,e.RowIndex]; dgcb.DataSource = filteredTerritoriesBS;

// Filter the BindingSource based upon the region selected 
    this.filteredTerritoriesBS.Filter = "RegionID = " + 
     this.dataGridView1[e.ColumnIndex - 1, e.RowIndex].Value.ToString(); 
} 

}

私人无效dataGridView1_CellEndEdit(对象发件人,DataGridViewCellEventArgs E) { 如果(e.ColumnIndex == this.territoryComboBoxColumn.Index) { //重置组合框小区向未过滤的BindingSource DataGridViewComboBoxCell dgcb =(DataGridViewComboBoxCell)dataGridView1 [e.ColumnIndex,e.RowIndex]; dgcb.DataSource = territoriesBindingSource; //未经过滤

this.filteredTerritoriesBS.RemoveFilter(); 
} 

}

回答

0

我发现vb-tips.com 提供soulution它似乎工作的伟大,并在加载形式 这里是我的代码过滤DGV; http://codepaste.net/wra8qw

+0

该链接不再有效。你能在这里发布解决方案吗? – 2011-04-11 11:27:51

相关问题