我有一个表格的gridview和另一个表格的组合框。如果我在组合框中选择一个值,该值应该传递给gridview。我怎样才能实现这个...
问问题
728 次
1 回答
0
你的问题细节太少,但作为一个建议,我会尝试放置一些代码,也许它会给你一些提示。
// In case if you're dealing with WinForms
// For WPF solution could have similar approach
public class DataGridForm : Form
{
private DataGrid _grid;
public DataGridForm()
{
InitializeComponent();// <-- here _grid is instantiated
}
public void LoadData(object data)
{
// load data into grid
// I don't know, could be smt like
DataGridCell cell = _grid.Cells[0,0];
cell.Value = data;
}
}
public class FormWithComboBox : Form
{
private ComboBox _comboBox;
public DataGridForm DataGridForm { get; set; }// value is set by some externat user
public FormWithComboBox()
{
InitializeComponent();// <-- here _grid is instantiated
// including handler for OnSelectedItemChanged event
}
private void _comboBox_OnSelectedItemChanged(object sender, EventArgs e)
{
DataGridForm.LoadData(_comboBox.SelectedItem);
}
}
于 2012-07-23T12:08:37.630 回答