Results 1 to 3 of 3

Thread: Datagridviewcombobox returns string instead of decimal causing a datagriderror event

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    2

    Datagridviewcombobox returns string instead of decimal causing a datagriderror event

    I have a datagridview with a combobox column where I set the values of the combobox.items to decimal values. When I select a value I get the dateerror event, and when I look at the value for the combobox column, it is a string, not a decimal, which I guess is what's causing the problem. If I add the values as type string it works. Can I not use a combobox if the values aren't strings?

    I tried adding the combobox items as decimals, but that causes the datagridview dataerror.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,665

    Re: Datagridviewcombobox returns string instead of decimal causing a datagriderror ev

    Maybe... maybe not... how are you adding them to the drop down?
    Also, what's the code you're using where the error happens?


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2024
    Posts
    2

    Re: Datagridviewcombobox returns string instead of decimal causing a datagriderror ev

    cbCol = CType(dgvFoodChoices.Columns("colNumber"), DataGridViewComboBoxColumn)
    For Each d As Decimal In Form1.dgvComboBoxItems
    cbCol.Items.Add(d.ToString)
    Next

    If I don't use d.tostring, just d, then when I click on the combobox and select an item, I'll get the datagridview data error. And when I trap that, and look at the value of the combobox, instead of being a decimal, it's a string, which is when I get the fault. Treating the values as strings everywhere fixes the problem, but seem unsatisfactory.

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