[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
Re: Tinyint in Datagridview Combobox
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.
Re: Tinyint in Datagridview Combobox
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.