Datagridviewcombobox returns string instead of decimal causing a datagriderror event

Dan Hinsley 0 Reputation points
2024-07-24T16:41:28.86+00:00

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.

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,666 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 29,106 Reputation points Microsoft Vendor
    2024-07-25T01:43:10.29+00:00

    Hi @Dan Hinsley ,

    You can set the combobox column's ValueTypr to Decimal to avoid this error.

            DataGridView1.Columns(0).ValueType = GetType(Decimal)
    
    

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments