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 Basic
  4. DataGridView acting strange all of a sudden [modified]

DataGridView acting strange all of a sudden [modified]

Scheduled Pinned Locked Moved Visual Basic
helpcsswpfwcf
5 Posts 2 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.
  • M Offline
    M Offline
    Marcus J Smith
    wrote on last edited by
    #1

    I have a DataGridView that has worked great for months and now there is something causing a RowError event. All it says is Value is not valid for the DataGridViewComboBoxCell and I have done work to alleviate one part of the issue which had something to do with the AllCells auto sizing option. The other issue is that instead of showing the value when it is truly in the list it is raising that event and everything is blank. It is raising the error during the initial row adding logic after binding the data grid and it seems to get itself caught in some kind of DataError loop.


    CleaKO

    "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

    modified on Tuesday, February 26, 2008 3:16 PM

    K 1 Reply Last reply
    0
    • M Marcus J Smith

      I have a DataGridView that has worked great for months and now there is something causing a RowError event. All it says is Value is not valid for the DataGridViewComboBoxCell and I have done work to alleviate one part of the issue which had something to do with the AllCells auto sizing option. The other issue is that instead of showing the value when it is truly in the list it is raising that event and everything is blank. It is raising the error during the initial row adding logic after binding the data grid and it seems to get itself caught in some kind of DataError loop.


      CleaKO

      "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

      modified on Tuesday, February 26, 2008 3:16 PM

      K Offline
      K Offline
      Kschuler
      wrote on last edited by
      #2

      Are you sure the data being bound to the grid is correct? I had this happen once and realized later I was passing null values because of a change in the SQL that brought my data back from the database. If it worked before and doesn't now, I'd guess it HAS to be the data that is the trouble. If you are sure that is not the case, perhaps more information could spark something for us, like how is your combobox column set up? Do you set the DataSource, DataPropertyName, DisplayMember, and ValueMember properties in code or at design time? And in what order? Hope this helps.

      M 1 Reply Last reply
      0
      • K Kschuler

        Are you sure the data being bound to the grid is correct? I had this happen once and realized later I was passing null values because of a change in the SQL that brought my data back from the database. If it worked before and doesn't now, I'd guess it HAS to be the data that is the trouble. If you are sure that is not the case, perhaps more information could spark something for us, like how is your combobox column set up? Do you set the DataSource, DataPropertyName, DisplayMember, and ValueMember properties in code or at design time? And in what order? Hope this helps.

        M Offline
        M Offline
        Marcus J Smith
        wrote on last edited by
        #3

        For this grid I add all items to the combobox with no filtering when I first open up the form like this.

        For Each sizeRow As DataRow In _SizesToFilter.Rows
        CType(uxDataGrid.Columns("uxSizeGrid"), DataGridViewComboBoxColumn).Items.Add(sizeRow("Size").ToString)
        Next

        Then when I filter I do the following.

        If filterCell.Value IsNot Nothing Then
        _SizesToFilter= _DataAccess.GetSizesFiltered(filterCell.Value.ToString)

                    sizeCell.DisplayMember = "Size"
                    sizeCell.DataSource = \_SizesToFilter
        
                    Dim sizeRows As DataRow() = \_SizesToFilter.Select("Size = '" & filterCell.Value.ToString.Trim & "'")
        
                    If sizeRows.Length > 0 Then
                        sizeCell.Value = sizeRows(0)("Size")
                    Else
                        If \_SizesToFilter.Rows.Count = 2 Then
                            sizeCell.Value = \_SizesToFilter.Rows(1)("Size").ToString
                        Else
                            sizeCell.Value = ""
                        End If
                    End If
                End If
        

        All of this is working and I checked the database, there are no NULL values and I havent changed the select statements in quite a while. The part that is breaking is after all of the values are added. It seems that the value is technically selected but the combobox does not show anything, it shows my blank option.


        CleaKO

        "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

        K 1 Reply Last reply
        0
        • M Marcus J Smith

          For this grid I add all items to the combobox with no filtering when I first open up the form like this.

          For Each sizeRow As DataRow In _SizesToFilter.Rows
          CType(uxDataGrid.Columns("uxSizeGrid"), DataGridViewComboBoxColumn).Items.Add(sizeRow("Size").ToString)
          Next

          Then when I filter I do the following.

          If filterCell.Value IsNot Nothing Then
          _SizesToFilter= _DataAccess.GetSizesFiltered(filterCell.Value.ToString)

                      sizeCell.DisplayMember = "Size"
                      sizeCell.DataSource = \_SizesToFilter
          
                      Dim sizeRows As DataRow() = \_SizesToFilter.Select("Size = '" & filterCell.Value.ToString.Trim & "'")
          
                      If sizeRows.Length > 0 Then
                          sizeCell.Value = sizeRows(0)("Size")
                      Else
                          If \_SizesToFilter.Rows.Count = 2 Then
                              sizeCell.Value = \_SizesToFilter.Rows(1)("Size").ToString
                          Else
                              sizeCell.Value = ""
                          End If
                      End If
                  End If
          

          All of this is working and I checked the database, there are no NULL values and I havent changed the select statements in quite a while. The part that is breaking is after all of the values are added. It seems that the value is technically selected but the combobox does not show anything, it shows my blank option.


          CleaKO

          "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

          K Offline
          K Offline
          Kschuler
          wrote on last edited by
          #4

          Could it be a DataType error? If I'm reading your code correctly, you are adding all sizes into the box as strings, but when you set them: sizeCell.Value = sizeRows(0)("Size") are you sure the sizeRows(0)("Size") is a string? Would adding a .ToString and maybe some trim (and ToUpper if these actually contain alpha characters) fix the issue? I'm guessing you checked this, but just in case you didn't, have you checked that your filter is returning one or two records all the time? You are setting the value to "" if the filtered rows come back with a count of 3 or more... Other than that, nothing obvious jumps out at me. Sorry. Hopefully someone else can see something I missed.

          M 1 Reply Last reply
          0
          • K Kschuler

            Could it be a DataType error? If I'm reading your code correctly, you are adding all sizes into the box as strings, but when you set them: sizeCell.Value = sizeRows(0)("Size") are you sure the sizeRows(0)("Size") is a string? Would adding a .ToString and maybe some trim (and ToUpper if these actually contain alpha characters) fix the issue? I'm guessing you checked this, but just in case you didn't, have you checked that your filter is returning one or two records all the time? You are setting the value to "" if the filtered rows come back with a count of 3 or more... Other than that, nothing obvious jumps out at me. Sorry. Hopefully someone else can see something I missed.

            M Offline
            M Offline
            Marcus J Smith
            wrote on last edited by
            #5

            The Data Types match but the issue seems to be happening during the initial value set during the data binding process before it ever gets to my code. It seems to be random and doesnt occur with all sets of data so this is very strange.


            CleaKO

            "Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)

            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