Results 1 to 6 of 6

Thread: SelectedRows Always 0

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    563

    SelectedRows Always 0

    searchResultsDataGrid.SelectedRows.Count always says 0 even when I click on a row. I have the selection mode set to FullRowSelect. Any ideas?
    vb Code:
    1. If String.IsNullOrEmpty(JC.Global.StudyForm.filename) And searchResultsDataGrid.SelectedRows.Count > 0 Then
    2.             JC.Global.StudyForm.defaultFilename = searchResultsDataGrid.SelectedRows(0).Cells(1).Value.ToString()
    3.         End If
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: SelectedRows Always 0

    What sort of grid is it exactly? I'm guessing a DataGridView but I don't see where you've actually made that clear. What happens if you select multiple rows? Also, do you really care about SelectedRows? Do you maybe just want the CurrentRow regardless?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    563

    Re: SelectedRows Always 0

    It is a DataGridView.

    searchResultsDataGrid.CurrentRow = Nothing
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,196

    Re: SelectedRows Always 0

    Quote Originally Posted by rex64 View Post
    searchResultsDataGrid.SelectedRows.Count always says 0 even when I click on a row. I have the selection mode set to FullRowSelect. Any ideas?
    vb Code:
    1. If String.IsNullOrEmpty(JC.Global.StudyForm.filename) And searchResultsDataGrid.SelectedRows.Count > 0 Then
    2.             JC.Global.StudyForm.defaultFilename = searchResultsDataGrid.SelectedRows(0).Cells(1).Value.ToString()
    3.         End If
    Where is this code located? Which Event/Procedure/Function? How do you know SelectedRows.Count is 0, where do you test it?

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    563

    Re: SelectedRows Always 0

    I put a brake point on the line inside of the If statement:
    searchResultsDataGrid.CurrentRow = Nothing

    vb Code:
    1. Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
    2. If String.IsNullOrEmpty(JC.Global.StudyForm.filename) Then
    3.                 JC.Global.StudyForm.defaultFilename = searchResultsDataGrid.CurrentRow.Cells(1).Value.ToString 'searchResultsDataGrid.SelectedRows(0).Cells(1).Value.ToString()
    4.             End If
    5. End Sub
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2006
    Location
    Florida, USA
    Posts
    563

    Re: SelectedRows Always 0

    I found the problem. I am dumb. I moved this to the bottom of my function and added a comment. This was the issue:
    vb Code:
    1. 'User is done with this form. EXITS. LOL <<<<<<<<<<<<
    2.         Close()
    I use VB .NET 2022. Currently developing StudyX educational software, PlazSales POS system and Yargis a space ship shooter game.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width