两个窗体,frmContractRemind和frmContractRenewal。第一个窗体中放了一个DataGridView控件, 第二个窗体放了一个ListBox控件。现在我想把从DataGridView中获取的值,传到第二个窗体中的ListBox控件中,而且要考虑如果第一个窗体中的DataGridView中的DataGridViewCheckBoxColumn全选的话,也要全部传到第二个窗体中的ListBox去。请各位大鸟帮帮忙,最好能能写个例子。
调试欢乐多
isi.bw = bw;
isi.dwea = e;
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、窗体间传值: //姓名列所有数据
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、通过挨个勾选,产生事件: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;