0

I have datagridview for showing working or non-working of weekly. Fisrt, when i binding with dataset then it choose automatic type to be checkboxColumn because a data from dataset is boolean type like below.

enter image description here

but I need to change it to be combobox compound with true and false value enter image description here

but it's have a problem because i can't add item "true or false" it error" datagridviewcomboboxcell value is not valid ". And I don't want to make dataset for store two value.it's waste.


Note: I will explain step by step

This is my database for filling in datagridview enter image description here

And I use this query for creating "weekly_scheduleTableAdapter" .It will select each day and flag(1 or 0)

enter image description here

                SELECT DISTINCT (SELECT  [nonworking_day_flag]
                                 FROM [dbo].[default_nonworking_days]
                                 WHERE [id] =1 ) AS Sun
                               ,
                                 (SELECT  [nonworking_day_flag]
                                  FROM [dbo].[default_nonworking_days]
                                   WHERE [id] =2 ) AS Mon 
                               ,........
                                  ....until Saturday....
                                    ....................
                FROM [dbo].[default_nonworking_days]

Result: enter image description here

After I created "weekly_scheduleTableAdapter" I just binding datagridview to dataset.

enter image description here

it's can fill data to gridview (See first picture above). But if I need to change a cell to be combobox what should I do? enter image description here

1 Answer 1

1

You cannot convert a check box column to a combo box column. If you want a combo box column then you have to add a combo box column. You need to add the column before binding, either in the designer or in code, and set the DataPropertyName property of that column to tell it what column of the data source to bind to. If you want an example of this, look here.

EDIT: I didn't read your full question in the first place but it seems that you know how to add a column. You don't have to bind that column to a DataSet or DataTable or anything else. You can bind it to a simple collection of custom-made objects if you like or you can even add directly to its Items collection, just as you can for a regular ComboBox control.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.