[英]C# Databases Form1 = Datagridview, Form2 = Details View UPDATE/EDIT Method
In my form1 i have my tblContacts in a datagridview, the user can click the button next/previous to navigate through the database. 在我的form1中,我的tblContacts在datagridview中,用户可以单击next / previous按钮以浏览数据库。 form1 also has an update button which leads to form 2 which is a details view of the same dataset from form1.
form1还具有一个更新按钮,该按钮会导致出现form 2,form 2是来自form1的同一数据集的详细视图。 Can someone tell me how i can make form2 automatically load the contact details of the specific contact that form1 datagridview has been selected on.
有人可以告诉我如何使form2自动加载已选择form1 datagridview的特定联系人的详细联系信息。
Thanks. 谢谢。
firstly: in your form2 class, create constructors which hold information from the datagrid, for example; 首先:在您的form2类中,创建保存数据网格中信息的构造函数。
public string variable1 {get;set;}
public int variable2 {get;set;}
// as long as they're public, it doesnt matter what you call them, or there type
//(just make sure that you're using the right type, for datagrid's, string is
//usually fine but you can always convert)
secondly: when you create a new instance of your form, you can then assign the variables to "pass" to your new form, like so 其次:当您创建表单的新实例时,可以将变量“分配”给新表单,如下所示:
Form2 form2 = new Form2();
form2.variable1 = dataSource[rowIndex]["columnName"]
form2.variable2 = dataSource[rowIndex2]["columnName2"]
to get the selected row index, do; 获取选定的行索引,执行;
dataTable.SelectedRows[0].Index;
instead of [rowIndex] 而不是[rowIndex]
From here, in your form2 you can use these values to do whatever you want with them 从这里开始,在您的form2中,您可以使用这些值对它们执行任何操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.