Tabpages databinding problem.

I have a tabcontrol with a few tabpages. On Page 1 I have successfully bound the textboxes to my dataset1.
with an identical procedure I have tried to bind the textboxes on Page 2 to the data in dataset2, however,
when the form is run, no data is displayed in the textboxes of Page 2. Any ideas why and how this can be solved?

Comments

  • : I have a tabcontrol with a few tabpages. On Page 1 I have successfully bound the textboxes to my dataset1.
    : with an identical procedure I have tried to bind the textboxes on Page 2 to the data in dataset2, however,
    : when the form is run, no data is displayed in the textboxes of Page 2. Any ideas why and how this can be solved?
    :

    Here's my code... can anyone suggest what's wrong with it?

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    'Setup the Tabcontrol
    Call TabControlSetup()

    End Sub


    Private Sub TabControlSetup()

    'Fill the datasets with the connected databases
    OleDbDataAdapter1.Fill(DataSet11, "Products"
    OleDbDataAdapter2.Fill(DataSet21, "Products"

    'Databind the Textbox on Tabpage1
    Call Tabpage1Binders()

    'Databind the Textbox on Tabpage2
    Call Tabpage2Binders()

    End Sub


    Private Sub TabPage1Binders()

    'Allow the TextBox on Tabpage 1 to have an individual binding context
    Textbox1.BindingContext = New BindingContext()


    'DataBind the Textbox on Tabpage1 to the Flavour column of the Products Table in Dataset11
    Textbox1.DataBindings.Add("Text", DataSet11, "Products.Flavour")


    'Set the Textbox1 binding context
    Dim BindContext01 As BindingManagerBase = Textbox1.BindingContext(DataSet11, "Products")


    'Set the initial row positions for the TextBox1 to obtain data from
    BindContext01.Position = 0

    End Sub


    Private Sub TabPage2Binders()

    'Allow the TextBox on Tabpage 2 to have an individual binding context
    Textbox2.BindingContext = New BindingContext()


    'DataBind the Textbox on Tabpage2 to the Flavour column of the Products Table in Dataset21
    Textbox2.DataBindings.Add("Text", DataSet21, "Products.Flavour")


    'Set the Textbox2 binding context
    Dim BindContext02 As BindingManagerBase = Textbox2.BindingContext(DataSet21, "Products")


    'Set the initial row positions for the TextBox2 to obtain data from
    BindContext02.Position = 0

    End Sub

  • : : I have a tabcontrol with a few tabpages. On Page 1 I have successfully bound the textboxes to my dataset1.
    : : with an identical procedure I have tried to bind the textboxes on Page 2 to the data in dataset2, however,
    : : when the form is run, no data is displayed in the textboxes of Page 2. Any ideas why and how this can be solved?
    : :
    :
    : Here's my code... can anyone suggest what's wrong with it?
    :
    : Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    :
    : 'Setup the Tabcontrol
    : Call TabControlSetup()
    :
    : End Sub
    :
    :
    : Private Sub TabControlSetup()
    :
    : 'Fill the datasets with the connected databases
    : OleDbDataAdapter1.Fill(DataSet11, "Products"
    : OleDbDataAdapter2.Fill(DataSet21, "Products"
    :
    : 'Databind the Textbox on Tabpage1
    : Call Tabpage1Binders()
    :
    : 'Databind the Textbox on Tabpage2
    : Call Tabpage2Binders()
    :
    : End Sub
    :
    :
    : Private Sub TabPage1Binders()
    :
    : 'Allow the TextBox on Tabpage 1 to have an individual binding context
    : Textbox1.BindingContext = New BindingContext()
    :
    :
    : 'DataBind the Textbox on Tabpage1 to the Flavour column of the Products Table in Dataset11
    : Textbox1.DataBindings.Add("Text", DataSet11, "Products.Flavour")
    :
    :
    : 'Set the Textbox1 binding context
    : Dim BindContext01 As BindingManagerBase = Textbox1.BindingContext(DataSet11, "Products")
    :
    :
    : 'Set the initial row positions for the TextBox1 to obtain data from
    : BindContext01.Position = 0
    :
    : End Sub
    :
    :
    : Private Sub TabPage2Binders()
    :
    : 'Allow the TextBox on Tabpage 2 to have an individual binding context
    : Textbox2.BindingContext = New BindingContext()
    :
    :
    : 'DataBind the Textbox on Tabpage2 to the Flavour column of the Products Table in Dataset21
    : Textbox2.DataBindings.Add("Text", DataSet21, "Products.Flavour")
    :
    :
    : 'Set the Textbox2 binding context
    : Dim BindContext02 As BindingManagerBase = Textbox2.BindingContext(DataSet21, "Products")
    :
    :
    : 'Set the initial row positions for the TextBox2 to obtain data from
    : BindContext02.Position = 0
    :
    : End Sub
    :
    :
    [red]*************************************************************[/red]

    [blue] In looking over your post I have some thoughts and questions:

    1.) Are you opening 2 data connections to the same database? If so, it may be an issue of the first connection locking out the second. I would recommend that you use one connection for both data adapters.

    2.) I would recommend that you change the settings on tab page 2 to be identical for tab page 1 (since 1 is working). If the data displays on page 2 then it is possible that the data set you have for page 2 is empty, therefore no data to display. If this is the case, recheck your query and connection.

    3.) Since you are binding on tabpages, you might need to assign the object to the BindingIndex of the GroupBox control.

    [purple](Courtesy of VB .NET Help)[/purple]
    Dim bcG1 As New BindingContext()
    Dim bcG2 As New BindingContext()

    groupBox1.BindingContext = bcG1
    groupBox2.BindingContext = bcG2

    textBox1.DataBindings.Add("Text", ds, "Customers.CustName")
    textBox2.DataBindings.Add("Text", ds, "Customers.CustName")

    groupBox1.BindingContext(ds, "Customers").Position += 1
    groupBox2.BindingContext(ds, "Customers").Position += 1


    Hope this helps[/blue]




  • Thanks for your reply. I'm using 2 data adaptors, with a single connection to the same datbase file. I've double checked that the contents of the second dataset are as expected by databinding a datagrid to it. Also if I databind a textbox on tabpage 1 to dataset 2 it works fine... it's only when the textbox sits on tabpage 2 does it come up blank.
    I'm also reluctant to use the groupbox control because i'm actually databinding several textboxes on each tabpage to different positions within the dataset and not all to the same position.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories