Change a column type to an checkbox

1 Answer 118 Views
GridView
Kobus
Top achievements
Rank 1
Iron
Kobus asked on 10 May 2022, 01:34 AM

Hi there

 

I have a column in my DataTable that is called "checked"

I want to make this a checkbox.

With this code it is not changing it:

                GridViewCheckBoxColumn checkboxcolumn = new GridViewCheckBoxColumn();
                checkboxcolumn.DataType = typeof(int);
                checkboxcolumn.Name = "checked";
                checkboxcolumn.FieldName = "checked";
                checkboxcolumn.HeaderText = "Checked?";
                this.grdIssueAcceptance.MasterTemplate.Columns.Add(checkboxcolumn);

With this it added the type nicely, but it is another field. I do not want to ADD a field. 

                GridViewCheckBoxColumn checkboxcolumn = new GridViewCheckBoxColumn();
                checkboxcolumn.DataType = typeof(int);
                checkboxcolumn.Name = "checked02";
                checkboxcolumn.FieldName = "checked02";
                checkboxcolumn.HeaderText = "Checked?";
                this.grdIssueAcceptance.MasterTemplate.Columns.Add(checkboxcolumn);

 

Regards

Kobus

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 10 May 2022, 09:43 AM

Hi Kobus,

Thank you for the provided image and code snippet.

I have checked this on my side and the column is created as expected. May I ask you to share the DataTable set-up so that I can check the data inside it and its column types?

Regards,
Dinko
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Kobus
Top achievements
Rank 1
Iron
commented on 14 May 2022, 12:29 AM

Hi Dinko

 

I share the DataTable below.

all the columns is string

Kobus
Top achievements
Rank 1
Iron
commented on 14 May 2022, 01:07 AM

Thank you Dinko.

 

I change the type to Int and it is working perfect now.

 

Thank you for your guidance.

Regards

Kobus

Dinko | Tech Support Engineer
Telerik team
commented on 16 May 2022, 09:20 AM

I am happy to hear that you have found a solution for your case. You are in the right direction. Basically, the checkbox expects the bool or int type of the values inside the DataTable column. If the column is a string it won't convert the value correctly. 
Tags
GridView
Asked by
Kobus
Top achievements
Rank 1
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or