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 6012197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:22:08+00:00 2026-05-23T02:22:08+00:00

I am not sure whether it is possible or not? need suggestion I want

  • 0

I am not sure whether it is possible or not? need suggestion

I want to display filenames from 2 different folders into 2 different DataGridview controls that are placed in 2 tab pages of TabControl1. Here is the code that I have tried. By running this code, I can able to show the filenames from a folder onto DataGridView1 in Tabpage1 but not in DataGridView2 of tabpage2.

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

    With DataGridView1
        .Columns.Add("Column 0", "TaskName")
        .AutoResizeColumns()
    End With
    With DataGridView2
        .Columns.Add("Column 0", "TaskName")
        .AutoResizeColumns()
    End With

    Dim rowint As Integer = 0
    Dim name As String
    Dim directoryInfo As New System.IO.DirectoryInfo("C:\Demo\Sample1")
    Dim fileInfo = System.IO.Directory.GetFiles(directoryInfo.ToString)
    For Each name In fileInfo

        DataGridView1.Rows.Add()
        Dim filename As String = System.IO.Path.GetFileName(name)
        DataGridView1.Item(0, rowint).Value = filename
        rowint = rowint + 1
    Next
End Sub

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.Click

    If (TabControl1.SelectedTab.Name.ToString) = "TabPage2" Then
        MessageBox.Show(TabControl1.SelectedTab.Name.ToString)
        Dim rowint As Integer = 0
        Dim name As String
        Dim directoryInfo As New System.IO.DirectoryInfo("C:\Demo\Sample2")
        Dim fileInfo = System.IO.Directory.GetFiles(directoryInfo.ToString)
        For Each name In fileInfo
            DataGridView2.Rows.Add()
            Dim filename As String = System.IO.Path.GetFileName(name)
            DataGridView1.Item(0, rowint).Value = filename
            rowint = rowint + 1
        Next
    End If

End Sub
  • 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-05-23T02:22:09+00:00Added an answer on May 23, 2026 at 2:22 am

    Here is your code (line numbers for reference):

    1) For Each name In fileInfo
    2)   DataGridView2.Rows.Add()
    3)   Dim filename As String = System.IO.Path.GetFileName(name)
    4)   DataGridView1.Item(0, rowint).Value = filename
    5)   rowint = rowint + 1
    6) Next
    

    Your error is coming from line 4, which is referencing the incorrect DataGridView control. It should be:

    4)   DataGridView2.Item(0, rowint).Value = filename
    

    With your code, you need to clear out the DataGridView2 every time you click on your second tab or else your data grid starts to expand with extra empty rows.

    Not sure it makes sense to have this code in the TabControl1 Click event– you might want to move this code to your Load event like you are doing with the first data grid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not sure whether it is possible to achieve this kind of implementation
HI all, I am not sure whether this is possible in C# or in
Not sure whether the title is misleading, but requirement is below. I need to
Not sure whether its a duplicate or not-why my left and right border are
I am not sure whether this only happens to me. Basically if I have
I'm not sure whether to post it here or at ServerFault. Anyway, I'm trying
I am not sure whether it has been disscussed before or not but I
I'm not sure whether or not this is the appropriate way of doing this,
I'm not sure whether this question belongs on StackOverflow or SuperUser, but here goes
I am not sure whether I am asking this with the right words, I

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.