我在一个表单中有一个gridview,在另一个表单中有一个组合框。如果我在组合框中选择一个值,那个值应该传递给gridview.how我可以实现这个...
答案 0 :(得分: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);
}
}