Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Studio
  4. VB - Adding to List(of String) from datagridview column/cell value

VB - Adding to List(of String) from datagridview column/cell value

Scheduled Pinned Locked Moved Visual Studio
cssdatabasequestioncareer
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PrissySC
    wrote on last edited by
    #1

    (SOLVED) I have played with this, but I am missing the obvious. Can I borrow your brains again? (I dislike working alone.) I make a selection in the datagridview. This selection is now processed in the make list handle. I bold the first column's text for identity on the datagridview. I want to keep the value from the cell in a list. I get out of range and null exceptions. At this point, I do not have the cleanest code as I am working on operational aspects of the grid. So, below the instruction to bold the selected, I am counting the bolded (which works fine) for a count value on the form to be displayed, but I cannot add the "job number" to my list. And before you ask, yes the job number is a string. I checked that first! Original declaration is ... dim selectedJobNo as list(of string)

    Private Sub MakeListToolStrip_Click_1(sender As Object, e As EventArgs) Handles MakeListToolStrip.Click

        Dim f As Font = New Font(JobsDataGridView.Font, FontStyle.Bold)
    
        For selectrow = 0 To JobsDataGridView.SelectedRows.Count - 1
            JobsDataGridView.SelectedRows(selectrow).Cells(0).Style.Font = f
    
        Next
    
        Dim i As Integer = 0
        Dim count As Integer = 0
        selectedJobNo = New List(Of String)
    
        For i = 0 To JobsDataGridView.Rows.Count - 1
    
            If JobsDataGridView.Rows(i).Cells(0).InheritedStyle.Font.Bold Then
                count = count + 1
                selectedJobNo.Add(JobsDataGridView.SelectedRows(i).Cells(0).Value.ToString)
                MsgBox(selectedJobNo.Count)
            End If
    
        Next
        JobSelectedToolStrip.Text = count
    
        'remove highlight selection and deselect any row highlight
        Me.JobsDataGridView.SelectionMode = DataGridViewSelectionMode.CellSelect
    End Sub
    

    Solution: I am leaving this post in case someone tries a similar method. However, I switched to a collection! I don't know why I didn't think of this. I am so very accustomed to just using a list. Here is what I did ... 1. When item selected in the DGV. I bolded the index/reference cell only. I add to the collection. 2. When removing an item from the custom selected list, I un-bold the index/reference cell. I remove from the collection. 3. When they switch between sorts, I run through the collection to bold the index/reference cells (because the DGV gets a new datasource selected based on the predefined sorts open/closed/all). 4. On request to print,

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups