以下代码要实现的功能是"通过双击DataGridView 中的列来引发邮件发送的操作"
代码如下:
//双击联系人发送邮件
int index = e.RowIndex; string DesStr = UserDgv.Rows[index].Cells["Column5"].Value.ToString();
//如果地址非空
if (!DesStr.Trim().Equals(""))
{
//根据选中的地址信息,初始化SendMailForm界面
SendMailForm newform = new SendMailForm();
newform.DesStr=DesStr;
newform.ShowDialog();
} }
另一个窗体:
public partial class SendMailForm : Form {
public string DesStr;
public SendMailForm()
{
InitializeComponent();
}
private void SendMailForm_Load(object sender, EventArgs e)
{
ResTbx.Text=DesStr; //根据选中的联系人信息填充本窗体的收件人信息 }
可是这样在调试的时候收件人文本框中得到的不是所选中的联系人的地址,而是数字,我该怎么解决啊
代码如下:
//双击联系人发送邮件
int index = e.RowIndex; string DesStr = UserDgv.Rows[index].Cells["Column5"].Value.ToString();
//如果地址非空
if (!DesStr.Trim().Equals(""))
{
//根据选中的地址信息,初始化SendMailForm界面
SendMailForm newform = new SendMailForm();
newform.DesStr=DesStr;
newform.ShowDialog();
} }
另一个窗体:
public partial class SendMailForm : Form {
public string DesStr;
public SendMailForm()
{
InitializeComponent();
}
private void SendMailForm_Load(object sender, EventArgs e)
{
ResTbx.Text=DesStr; //根据选中的联系人信息填充本窗体的收件人信息 }
可是这样在调试的时候收件人文本框中得到的不是所选中的联系人的地址,而是数字,我该怎么解决啊
还有双击的事件你用的是哪个?你确定你的列名写对了吗?
Column5是地址列吗?
2.另外不建议你这样来进行数据传递,在一个类中尽量避免使用共有的变量。你可以这样些
string DesStr = UserDgv.Rows[index].Cells["Column5"].Value.ToString();
//如果地址非空
if (!DesStr.Trim().Equals(""))
{
//根据选中的地址信息,初始化SendMailForm界面
SendMailForm newform = new SendMailForm(DesStr ); // 作为参数进行传递。
newform.ShowDialog();
} }
另一个窗体:
public partial class SendMailForm : Form {
private string DesStr; // 改为私有,
public SendMailForm(string oriStr) // 在此构造时传入地址
{
DesStr = oriStr;
InitializeComponent();
}
private void SendMailForm_Load(object sender, EventArgs e)
{
ResTbx.Text=DesStr; //根据选中的联系人信息填充本窗体的收件人信息 }
看看你的Cells["Column5"]对应的是哪一列