Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8583653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:35:20+00:00 2026-06-11T21:35:20+00:00

I am adding a tab page and datagridview to a Tab Control for every

  • 0

I am adding a tab page and datagridview to a Tab Control for every record in a datatable.

I would like to have a new Tab/DataGridView for each record (there will be ~3 for right now). I am declaring a new DataGridView D. How do I refer to these controls later?

I will want to do things like save changes in the datagridview to the database. Currently I can get the data on the screen and it looks good, but I believe I am not adding the DataGridView controls correctly because I keep re-using “D” as the control.

            Dim dt As New DataTable

        GetDataTable("SELECT * FROM aFeeTypes DescSeq", dt)

        Dim i As Integer

        'for each class in the datatable add a tab and a datagridview
        For i = 0 To dt.Rows.Count - 1

            Dim dr As DataRow
            dr = dt.Rows(i)

            Dim D = New DataGridView
            D.Visible = True

            Dim tp As New TabPage
            tp.Name = "tp" & i
            tp.Text = dr.Item("Desc2")
            frmUI.tcFee.TabPages.Add(tp)
            frmUI.tcFee.TabPages(i).Controls.Add(D)

            dgv_Fill(D, "SELECT * FROM Fee WHERE ClassID=" & dr.Item("ClassID") & " ORDER BY Seq")

            D.AutoResizeColumns()
            D.Width = tp.Width
            D.Height = tp.Height

        Next i

this does not work:

            With frmUI.Controls("D" & i)
                .AutoResizeColumns()
                .Width = tp.Width
                .Height = tp.Height
            End With
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:35:22+00:00Added an answer on June 11, 2026 at 9:35 pm

    I found a solution to the problem. The problem is that the new row has an autonumber ID.

    When da.update(dt) occurs, the new row is inserted to the database. The database knows the new autonumber ID. However, the datatable does not.

    For the datatable to know, the dataadapter is refilled. However, this causes the datatable to have all the old rows plus all the new rows and they all appear in the datagridview.

    By clearing the old rows from the datatable, the fill refreshes all the data in the datatable and therefore refreshes the datagridview.

        Public Sub dgv_AddRow(ByVal dgvName As String)
    
        Dim dgv As DataGridView = colDataGridView.Item(dgvName)
    
        Dim da As SqlDataAdapter = colDataAdapter.Item(dgvName)
        Dim dr As DataRow = frmUI.allDataSet.Tables(dgvName).NewRow
    
        'autopopulate the class id
        dr("ClassID") = dgv.Parent.Tag
    
        'add the new row
        frmUI.allDataSet.Tables(dgvName).Rows.Add(dr)
    
        'get the changed table
        Dim dt As DataTable = frmUI.allDataSet.Tables(dgvName)
    
        'inserts the new row to the database.  concurrency violation 
        'will occur because datatable does not know the new Autonumber ID for the new row.
    
        da.Update(dt)
    
        'remove the datatable rows so they can be replaced using the adapter fill
        'if rows are not cleared, following fill causes datatable to 
        'have existing rows plus all the rows again due to the fill
    
        frmUI.allDataSet.Tables(dgvName).Rows.Clear()
    
        'refill the adapter (refill the table)
        'Everything you do to the underlying dataTable
        'gets displayed instantly on the datagridview
    
        da.Fill(frmUI.allDataSet, dgvName)
    
    
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i m adding new jquery ui tabs to a tab the sample page (click
I have a tab control on a page; its items are bound back to
Possible Duplicate: Adding a Tab to facebook page I have created a Facebook app
I'd like to add a new tab to the 'catalog->manage products->product information' page in
I have a form that contains a tab canvas. On the second canvas page
In GWT , there is a way to change the tab title Window.setTitle(new Title)
I am trying to create a tab-like interface where I will switch views by
I have a repeater which dynamically generate tab links using Sitecore (sc:Link) like this:
I have built two control containers on a page, one is using jquery-ui tabs
I am adding some custom tabs to a jquery ui tab control. $(#tabs).tabs(add,#tabContent0,CLICK ME

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.