TextBox にいくつかのデータを入力し、form2 のコンボボックスで項目を選択しましたが、form1 で同じデータを使用したいのですが、どうすればよいでしょ
うか....このコード
frmConfig
は form2 でtxtSrcIP
、TextBox です。
public partial class Form1 : Form
{
frmConfig f2 = new frmConfig();
public Form1(frmConfig Cont)
{
f2 = Cont;
}
String SIp = f2.txtSrcIP.text;
}
この行にエラーが表示されてString SIp = f2.txtSrcIP.text;
います。フィールド初期化子は非静的フィールドメソッドまたはプロパティを参照できません
frmConfig 本体 public partial class frmConfig : Form { private Form1 f1;
public frmConfig()
{
InitializeComponent();
}
private void btnConnect_Click(object sender, EventArgs e)
{
// Open connection to the database
string conString = "server="+txtSrcIP.Text+";uid="+txtSrcUserId.Text+";pwd="+txtSrcPwd.Text;
using (SqlConnection con = new SqlConnection(conString))
{
con.Open();
// Set up a command with the given query and associate
// this with the current connection.
using (SqlCommand cmd = new SqlCommand("SELECT name from sys.databases", con))
{
using (IDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
cbSrc.Items.Add(dr[0].ToString());
}
}
}
}
private void btnNext_Click(object sender, EventArgs e)
{
if (cbSrc.SelectedItem != null && cbSrc.SelectedItem != "" && cbDest.SelectedItem != null && cbDest.SelectedItem != "")
{
this.Hide();
//Form1 f1 = new Form1();
f1.Show();
this.Close();
}
else
{
MessageBox.Show("Enter all the details");
}
}
}
これが私がやっていることなので、form1 にすべてのテキストボックスとコンボックスの値が必要です