如何将listview项目转移到另一个表单?
借助一些YouTube视频,我能够将数据库中的数据检索并显示到列表视图中。现在我的问题是:
我想点击列表视图中的1行,当我点击编辑/查看按钮时,该行的数据将插入到那些文本框中,组合框等。
基本上,我想选择一行并以另一种形式查看。
我尝试过:
With the help of some youtube videos, I was able to retrieve and display data from the database into the listview. Now my problem is:
I want to click 1 row in the listview and when I click the edit/view button the data from that row would be inserted into those textboxes, comboboxes, etc.
Basically, I want to select a row and view it in another form.
What I have tried:
I used this code to view the data from the database into the listview:
<pre> private void loadtblsupp()
{
cn.Open();
cmd.CommandText = "select * from SupplierTable";
cmd.Connection = cn;
dr = cmd.ExecuteReader();
while (dr.Read())
{
ListViewItem item = new ListViewItem(dr["Supp_ID"].ToString());
item.SubItems.Add(dr["Supp_Name"].ToString());
item.SubItems.Add(dr["Supp_Address"].ToString());
item.SubItems.Add(dr["Supp_CPerson"].ToString());
item.SubItems.Add(dr["Supp_TelNo"].ToString());
item.SubItems.Add(dr["Supp_FaxNo"].ToString());
item.SubItems.Add(dr["Supp_Email"].ToString());
supplier_tb.Items.Add(item);
}
cn.Close();
}
具体取决于两种形式之间的关系。
看看这些,其中一个适合你的情况。
创建另一个实例的表格:
Exactly how depends on the "relationship" between the two forms.
Have a look at these, one of them will fit your circumstances.
The form that creates an instance of another:
MyForm mf = new MyForm();
mf.Show();
是父,另一种形式是孩子。
(这并不意味着任何正式的MDI关系)
转让两种表格之间的信息,第1部分:父母与子女 [ ^ ]
在两种表格之间传递信息,第2部分:儿童到父母 [ ^ ]
在两种形式之间传递信息,第3部分:儿童到儿童 [ ^ ]
Is the "parent", the other form is the "child".
(This doesn't imply any formal MDI relationship)
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]