One of my DB column is a char(1). I use it to report "y" or "n" for a row.
I've added GridView which has a combobox column.
I used dataset to connect between the two.
How to I change the "true" of "false" which the combobox returns to a "y" or "n" value?
Now when I change the value of "Active" combobox (see image attached), an exception thrown "Cannot set column 'bool_active'. The value violates the MaxLength limit of this column."
10 Answers, 1 is accepted
This happens because the type of your column is char(1), why don't you use bit datatype for this?
Hope this helps, if you have any other questions or comments, please let me know,
Telerik WinForms MVP
What do you mean bit data type?
My database column is indeed varchar(1), and I want it to receive 'y' or 'n' only.
I need the combobox to be checked if column is 'y' and unchecked if value retrieved is 'n'.
I didn't understand your answer. How do I implement it?
There are two ways to do this. The more obvious route is to convert your Y/N to a Bit as it comes out of your database so that the checkbox column renders correctly. In fact, I would advise changing your database column to a bit column and only having Y/N on the UI side. Storing Y/N in your database is slower to index and more cumbersome for these types of scenarios.
The other way would be to use a Type COnverter as I mentioned above.
Please think about something else, databases should be constructed in such a way so that data can be accessed as fast as possible. So because of this, if you would need to just get all the records that are true or all the records that are false, a query using a bit data type or a boolean in c# or vb will always be much faster than a string / char comparison. If you would just change that type in your table you will see that everything will work. But you won't have Y / N you will have 1/0 or true / false.
In my point of view this is the way to go, but if you really really want to go with Y / N i will provide you with a solution to do just that.
Please let me know what you decide.
Telerik WinForms MVP
But, how cant I convert the value retrieved/given from/to the db?
Anyway can you provide me a suggestion for a solution?
Another option, other than those that Emanuel and I have already suggested is to convert the value to a bit value as it comes out of the database in your SQL Stored Procedure or SQL Command text.
Hope that helps
In addition to Richard's and Emanuel's answers, you can read this documentation article that illustrates how you can make your data source compatible with a concrete column (in your case GridViewCheckBoxColumn). In addition, you can take a look at our Examples application, Convert Values section.
the Telerik team
I have succeed! I've used the information about Converting Data Types you've attached.
I've made a new class ToggleStateConverter and added to the checkbox the command
gridViewCheckBoxColumn1.DataTypeConverter = new ToggleStateConverter();
I've noticed to a new problem!
Everytime I go back to the Main Form Design, the above line is just removed automatically! and the properties for gridViewCheckBoxColumn1 comes back to default.
Look at the attached files. the first, before.jpg, was taken before touching "frmMain.cs [Design]", and after.jpg after clicking on it, and returning back to the designer cs file.
I believe it happens due to an automatic refresh coming with the radGridView.
How do I fix it???
You should not set the DataTypeConverter property of the column at design time. Instead, you should set it at run time. You can do that in the constructor of the form or in the Load event of form.Greetings,
the Telerik team