我已经设置了一个2表单载入一个datagridview,并且用户单击视图以选择他们想要的值。我可以在datagridview的同一窗体中获得显示在消息框内的值但是,当我尝试将它传递给另一个窗体时,它显示为NULL。我将如何让它显示在文本框内。这是我的代码。当我调试代码时,它首先正确传递值,但是当它完成运行时,它显示为空值。我已经尝试了很多不同的方法来做到这一点,试图在不同的类上使用公共变量。将字符串从datagridview传递到另一种形式的文本框
与文本框
public void FillTextBoxes(object sender, EventArgs e, string SupplierID)
{
supplierVO _SupplierVo = new supplierVO();
ListOfSuppliers _ListOfSuppliers = new ListOfSuppliers();
SupplierID = _ListOfSuppliers.SupplierCode;
MessageBox.Show(SupplierID);
txtSupplierCode.Text = SupplierID;
}
窗体2与DataGridView的
// Links to the user double click of the datagrid
public void SelectGridInformation (object sender, EventArgs e)
{
ChangeSupplierInfo _ChangeSupplerInfo = new ChangeSupplierInfo();
supplierVO _SupplierVO = new supplierVO();
Int32 selectedRowCount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected);
string SelectedSupplierID = dataGridView1.SelectedCells[0].Value.ToString();
SupplierCode = SelectedSupplierID;
_SupplierVO.SupplierCode = SelectedSupplierID;
_ChangeSupplerInfo.FillTextBoxes(sender, e, SelectedSupplierID);
this.Close();
}
我一直在试图用get和set属性的在这里做这一个表是该代码示例。
public string SupplierCode
{
get
{
return _SupplierCode;
}
set
{
_SupplierCode = value;
}
}
我的猜测是,你想用你的'ListOfSuppliers'类的现有实例,而不是创建的例如。 – PhoenixReborn
最好的方法是通过使用某种消息传递实现来分离功能,然后使用发布者/订户模型。 –
你在代码中放置了'FillTextBoxes'函数? – Fabio