Results 1 to 5 of 5

Thread: [RESOLVED] Tinyint in Datagridview Combobox

  1. #1

    Thread Starter
    Member Cyrax.NET's Avatar
    Join Date
    Feb 2007
    Posts
    54

    Resolved [RESOLVED] Tinyint in Datagridview Combobox

    Hi,

    I have a bound datagridview on a form. The designer has added a column from my SQL DB(type tinyint) as a textbox colum. Now i'd like the cell to be displayed as a combobox column since its a month value column e.g. 0-12.

    Through the designer I changed the column type to Combobox(which means the column is no longer bound) but when I try to load the form now its always coming back with a "Object reference not set to an instance of an object". The annoying thing is VS is not telling me exactly which line of code is bringing back this error but it does show me the stacktrace which points to the designer code.

    *I've made sure to add all the possible combinations in the combobox column's items list*

    I've been doing some research and some people point to tinyint dataype not being 'liked' in vb.net so a direct cast needs to be done. However since am doing this in the designer am not quite sure where exactly to cast?, assuming to type Byte? Going through the designer generated code I can see its already doing a cast of its own:

    Code:
    DataGridViewCellStyle9.Font = New System.Drawing.Font("Calibri", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Any help would be greatly appreciated as I've got a few more colums similar.

    Cheers

  2. #2

    Thread Starter
    Member Cyrax.NET's Avatar
    Join Date
    Feb 2007
    Posts
    54

    Re: Tinyint in Datagridview Combobox

    *bump*
    Please mark your thread as Resolved; it helps identify which posters still require assistance and keeps things nice & tidy
    Acknowledge a helpful post; keeps the community going

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Tinyint in Datagridview Combobox

    Have you bound the list of possible values to the column? If you've got a combo box column then you need a list of values in the combo box. Follow the CodeBank link in my signature and find my thread on combo box columns in DataGridViews.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: Tinyint in Datagridview Combobox

    Retracted

  5. #5

    Thread Starter
    Member Cyrax.NET's Avatar
    Join Date
    Feb 2007
    Posts
    54

    Re: [RESOLVED] Tinyint in Datagridview Combobox

    Thanks jmcilhinney, I used your codebank example and changed my tinyint column to use a display member/value member source.
    I would of done this if I had dynamic lookups for the combobox and perhaps point it to a table in my DB but because my values are static I thought using the combobox's item list collection would be the quick approach.

    What I don't understand is why using item list approach for string value's worked fine but for integer values it would through the error?

    Anyone else who may encounter this problem, don't forget to double check your DB data types against those a) in your datasets b) in your datagridview.

    Cheers.
    Please mark your thread as Resolved; it helps identify which posters still require assistance and keeps things nice & tidy
    Acknowledge a helpful post; keeps the community going

Tags for this Thread

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