以下是引用shangsharon在2013-11-5 16:15:57的发言:
最简单实用的是在跳出的窗体中添加一个构造函数,
例如:public EditForm(string s1,string s2,.....,string s6)
{
TextBox1.Text=s1;
TextBox2.Text=s2;
......
TextBox6.Text=s6;
}
当你单击修改按键时代码改为:
//获取6列的文本,分别赋值给s1,s2,s3.....
EditForm f = new EditForm(s1,s2,.....,s6)
还是挺感谢的!我是这样写的,也可以
FORM1
private void button4_Click(object sender, EventArgs e)
{
try
{
ListViewItem Item = listView1.SelectedItems[0];
string simNo = Item.SubItems[0].Text;
string startHoure = Item.SubItems[1].Text;
string startMinute = Item.SubItems[2].Text;
string endHoure = Item.SubItems[3].Text;
string endMinute = Item.SubItems[4].Text;
string retSpan = Item.SubItems[5].Text;
FrmSimChange changesimno = new FrmSimChange();
changesimno.CSimNo = simNo;
changesimno.CStartHour = int.Parse(startHoure);
changesimno.CStartMinute = int.Parse(startMinute);
changesimno.CEndHour = int.Parse(endHoure);
changesimno.CEndMinute = int.Parse(endMinute);
changesimno.CRetSpan = int.Parse(retSpan);
if (changesimno.ShowDialog() == DialogResult.OK)
{
Item.SubItems[1].Text = changesimno.CStartHour.ToString();
Item.SubItems[2].Text = changesimno.CStartMinute.ToString();
Item.SubItems[3].Text = changesimno.CEndHour.ToString();
Item.SubItems[4].Text = changesimno.CEndMinute.ToString();
Item.SubItems[5].Text = changesimno.CRetSpan.ToString();
}
}
catch
{
MessageBox.Show("请选择需要修改的号码");
return;
}
finally
{
}
}
FORM2
public partial class FrmSimChange : Form
{
public FrmSimChange()
{
InitializeComponent();
}
private void FrmSimChange_Load(object sender, EventArgs e)
{
}
public string CSimNo
{
get
{
return tBsnc.Text;
}
set
{
tBsnc.Text = value;
}
}
public int CStartHour
{
get
{
return int.Parse(tBshc.Text);
}
set
{
tBshc.Text = Convert.ToString(value);
}
}
public int CStartMinute
{
get
{
return int.Parse(tBsmc.Text);
}
set
{
tBsmc.Text = Convert.ToString(value);
}
}
public int CEndHour
{
get
{
return int.Parse(tBehc.Text);
}
set
{
tBehc.Text = Convert.ToString(value);
}
}
public int CEndMinute
{
get
{
return int.Parse(tBemc.Text);
}
set
{
tBemc.Text = Convert.ToString(value);
}
}
public int CRetSpan
{
get
{
return int.Parse(tBrsc.Text);
}
set
{
tBrsc.Text = Convert.ToString(value);
}
}
private void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}
}