Hello,
I have a tabcontrol with 4 tabpages with some textboxes on each tabpage.These textboxes are binded to a datatable.All the data appears well in each textbox but when i want to access the text property of the textboxes alle the values are empty except the text propertys on tabpage 1?Why is that?
Here is some code:
public partial class Form1 : Form{
public DataSet ds = new DataSet(); public DataTable dt = new DataTable(); public BindingSource binding1 = new BindingSource(); public Form1(){
InitializeComponent();
toolStripProgressBar1.Maximum = 10;
toolStripProgressBar1.Minimum = 0;
toolStripProgressBar1.Value = 0;
toolStripProgressBar1.Step = 1;
try{
string connectString = "Persist Security Info=False;User ID=gerry;Password=3600gerry;Initial Catalog=BROEKX_038951_311;Data Source=webdata99.broekx.be"; string sql = "Select * From [038951_311_PERSON_PERSON]"; using (SqlConnection connection = new SqlConnection(connectString)){
connection.Open();
SqlDataAdapter dataAdapter1 = new SqlDataAdapter(sql, connection);dataAdapter1.Fill(ds,
"038951_311_PERSON_PERSON");dt = ds.Tables[
"038951_311_PERSON_PERSON"];binding1.DataSource = dt;
connection.Close();
}
}
catch (SqlException sqlex){
MessageBox.Show(sqlex.Message, "Error");}
catch (Exception ex){
MessageBox.Show(ex.Message, "Error");}
}
public partial class Personeel : Form
{
Form1 frm1 = (Form1)Application.OpenForms["Form1"];public
Personeel(){
InitializeComponent();
bindingNavigator2.BindingSource = frm1.binding1;
}
private
void VulTextboxen(){
this
.textBox1.DataBindings.Add(new Binding("Text", frm1.binding1, "AFKORTING", true)); this.textBox2.DataBindings.Add(new Binding("Text", frm1.binding1, "NAAM", true));this
.textBox38.DataBindings.Add(new Binding("Text", frm1.binding1, "PLAAT", true)); this.textBox49.DataBindings.Add(new Binding("Text", frm1.binding1, "BURGSTAND", true));
}
so textbox 1 and 2 are on tabpage 1 and have a text property but textbox 38 and 49 are on tabpage 4 and have empty text property.
Hope someone can help
greetings, gerry
gerry veltjenPosted Apr 17, 2009, 4:05 PM
Thank you both for the replies,
I will try that.
thanx gerry
Satish KathiPosted Apr 17, 2009, 10:21 AM
Try this
private void Form2_Load(object sender, EventArgs e)
{
foreach (TabPage tp in tabControl1.TabPages)
tabControl1.SelectTab(tp);
tabControl1.SelectTab(0);
}
Ashley ArgilePosted Apr 16, 2009, 9:02 AM
I tried creating a sample app to reproduce the behaviour that you were experiencing but I was unable to - The text boxes were all correctly populated. There were three main differences in my app i) I only had one form and wasn't sharing a binding, ii) I generated my datarows locally instead of retrieving them from a database & iii) I only had two tab pages.
Is the relevant data definitely visible in the dataset (i.e. When you debug)? You could insert some code such as ((DataRowView)frm1.binding1.Current).Row to look at the current row and check it's contents are as expected from the Personeel class.
Regards
Ashley
p.s.
If you want to see the sample I produced then I'm quite happy to send it to you.