窗体间的传值问题
两个窗体,frmContractRemind和frmContractRenewal。第一个窗体中放了一个DataGridView控件, 第二个窗体放了一个ListBox控件。现在我想把从DataGridView中获取的值,传到第二个窗体中的ListBox控件中,而且要考虑如果第一个窗体中的DataGridView中的DataGridViewCheckBoxColumn全选的话,也要全部传到第二个窗体中的ListBox去。请各位大鸟帮帮忙,最好能能写个例子。 --------------------编程问答-------------------- 补充下 最前面的一列是复选框,后面有合同编号、姓名、签订时间等等,我要获取的每一行中的姓名怎么做 --------------------编程问答-------------------- 点击窗体A中的某个控件,弹出了窗体B
A中的数据传到B中
那么在B窗体被创建的时候,将A中的值赋给在B中定义的属性
在B中通过属性访问
例如
--------------------编程问答--------------------
ImportStockInfo isi = new ImportStockInfo();
isi.bw = bw;
isi.dwea = e;
你这样讲的太抽象了
还是不懂 --------------------编程问答-------------------- 求各位老鸟进来 跪求解释 求例子 --------------------编程问答-------------------- 1、获取“姓名”列的所有数据:
int iNameColumnNum=2;//姓名在第几列
int iCount = this.dataGridView1.Rows.Count;
string[] sName=new string[1000];
if (iCount != 0)
{
for (int i = 0; i < iCount; i++)
{
sName[i]=this.dataGridView1[iNameColumnNum, i].Value;
}
}
2、窗体间传值:
--------------------编程问答-------------------- 两个窗体,frmContractRemind和frmContractRenewal。第一个窗体中放了一个DataGridView控件, 第二个窗体放了一个ListBox控件。现在我想把从DataGridView中获取的值,传到第二个窗体中的ListBox控件中,而且要考虑如果第一个窗体中的DataGridView中的DataGridViewCheckBoxColumn全选的话,也要全部传到第二个窗……
//姓名列所有数据
public string[] sName=new string[1000];
public string[] SName
{
get { return SName; }
set { SName = value; }
}
//打开第二个窗体
Form2 form2 = new Form2();
form2.Owner = this;
form2.Show();
//第二个窗体Form1_Load事件中
string[] sName2=new string[1000];
Form1 fForm = (Form1)this.Owner;
sName2 = fForm.SName;
1、添加“toolStripButton”按钮,则做此按钮的单击事件:
private void toolStripButton_Click(object sender, EventArgs e)
{
int iCount = this.dataGridView1.Rows.Count;
if (iCount != 0)
{
for (int i = 0; i < iCount; i++)
{
b[i] = true;//哪些行的姓名需要在第二个窗体显示的标记,通过窗体传递
this.dataGridView1[0, i].Value = true;
}
this.pictureBox1.Refresh();
}
}
2、通过挨个勾选,产生事件:
--------------------编程问答-------------------- public static class test
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if ((e.RowIndex >= 0) && (e.ColumnIndex >= 0))//列表为空时不响应
{
DataGridViewColumn column = this.dataGridView1.Columns[e.ColumnIndex];
int currentRowIndex = this.dataGridView1.CurrentRow.Index;//选中的当前行
//所有CheckBox列
if (column is DataGridViewCheckBoxColumn)
{
if (e.RowIndex == currentRowIndex && e.ColumnIndex == 0)//选中行、第0列
{
DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)this.dataGridView1.Rows[currentRowIndex].Cells["Column1"];
Boolean flag = Convert.ToBoolean(checkCell.Value);
if (flag == true) //CheckBox被选中
{
//勾选事件
}
else
{
//未勾选事件
}
}
}
}
}
{
public static string value;
}
第一个窗体:
test.value=datagridview.Rows[i].Tostring();
窗体二:
ListBox.Item.Add(Test.value); --------------------编程问答-------------------- 第一个窗口:
frmContractRemind f1=new frmContractRemind ();
f1.ShowLb=list;
f1.Show();
第二个窗口添加 这个属性
public List<string> ShowLb
{
get
{
return list;
}
set
{
list = value;
for (int n = 0; n < list.Count; n++)
listBox1.Items.Add(list[n]);
}
}
private List<string> list=null;
--------------------编程问答-------------------- 学习了…… --------------------编程问答--------------------
你所说的两个窗体是都打开着的,还是有一个是需要点击按钮弹出来。如果是后者就简单很多,你可以直接从构造方法将值传递过去。如果是前者,可以在触发事件里遍历Application.OpenForms找到你想要的赋值的窗体,找到后直接对控件赋值 --------------------编程问答-------------------- 怎么没人回答了
补充:.NET技术 , C#