Unable to Fetch Textbox values before ShowDialog in winforms
-
martedì 1 maggio 2012 10:45
//Form1 Code. That calls form2 public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Form2 objDlg = new Form2(); SqlConnection con = new SqlConnection("connectionstring"); SqlDataAdapter dap = new SqlDataAdapter("select * from employee where id =1", con); dap.Fill(objDlg.ds); objDlg.LoadData(); } }
//Form 2 Code public partial class Form2 : Form { public DataSet ds = new DataSet(); public Form2() { InitializeComponent(); } public void LoadData() { textBox1.DataBindings.Add("Text", ds.Tables[0], "FirstName"); if (textBox1.Text != "") { //I am not able to enter this block, even though i have value in my dataset. //But the text box is getting the value when it opens. i mean after showdialog box. checkBox1.Checked = true; } this.ShowDialog(); } }I have Form1 and Form2. I am calling Form2 from Form1. I am binding the controls in form2 using a datasource. I have two controls in form2, a text box and a check box. I want to enable the check box based on the content available in text box. But its not working. Look the code above to get more clarity.
Thanks in advance,
Ganesh
- Spostato Reed KimbleMicrosoft Community Contributor martedì 1 maggio 2012 16:24 C# in VB forum (From:Visual Basic Language)
Tutte le risposte
-
martedì 1 maggio 2012 12:14
Hello Ganesh Kumar Nagarajan,
Welcome to Msdn Forum , this is VisualBasic Forum , try to ask in decidated Forum For C#.
http://social.msdn.microsoft.com/Forums/it-IT/csharplanguage/threads
Regards.
-
martedì 1 maggio 2012 14:54
well, first thing I would try, is adding a public property to access CheckBox1, and see if that helps. the object should exist after the InitializeComponent() call, but it may not be accessible.- Contrassegnato come risposta Bob ShenMicrosoft Contingent Staff, Moderator mercoledì 9 maggio 2012 02:28
-
martedì 1 maggio 2012 16:24
At the point you read the textbox value, the databinding has not occured yet (the form is not yet visible).
Just read the underlying value that the textbox is bound to and don't worry about the databinding at this point in the form's life cycle.
Also, I'll move this to the C# general forum since the code is not VB...
-edit- sorry I meant at the point you read the textbox, not checkbox
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
- Modificato Reed KimbleMicrosoft Community Contributor martedì 1 maggio 2012 22:11
- Contrassegnato come risposta Bob ShenMicrosoft Contingent Staff, Moderator mercoledì 9 maggio 2012 02:28
-
martedì 1 maggio 2012 17:15
In order to enable checkbox, try this:
checkBox1.Enabled = ! string.IsNullOrWhiteSpace( textBox1.Text );
- Contrassegnato come risposta Bob ShenMicrosoft Contingent Staff, Moderator mercoledì 9 maggio 2012 02:28

