This is a migrated thread and some comments may be shown as answers.

how can i show checkbox column

3 Answers 647 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeongmin
Top achievements
Rank 1
Jeongmin asked on 08 Aug 2013, 04:53 AM
Hi. I have a problem. 

I have a DataTable ;
DataTable  IsChecked column datatype is string(DB type is varchar. I use oracle db) and Data is Y OR N

I want show this data in RadGridview with checkbox column .

I coded below. but ToggleStateConverter any method not call.
Wha's wrong? Help me.

I buy DevCraft Complete product. I want your reply  24 h response.
 


(User defined class and attach Attribute Sample is well work.)
ex)
            this.radGridView1.AutoGenerateColumns = true;

            this.radGridView1.DataSource = dsResult.Tables[0];   
            var checkBoxColumn = new GridViewCheckBoxColumn();
            checkBoxColumn.HeaderText = " IsChecked ";
            checkBoxColumn.Name = " IsChecked ";
            checkBoxColumn.Width = 100;
            checkBoxColumn.IsVisible = true;
            checkBoxColumn.DataType = typeof(string);
            checkBoxColumn.DataTypeConverter = new ToggleStateConverter();

            this.rndGridView1.Columns[0] = checkBoxColumn;








3 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 12 Aug 2013, 03:53 PM
Hello Jeongmin,

Thank you for writing.

You cannot assign a new instance to a column that has already been added to RadGridView. You should hide the autogenerated column and insert the new column on the index where you want to see it.
this.radGridView1.AutoGenerateColumns = true;
this.radGridView1.DataSource = dsResult.Tables[0];  
var checkBoxColumn = new GridViewCheckBoxColumn();
checkBoxColumn.HeaderText = " IsChecked ";
checkBoxColumn.FieldName= " IsChecked ";
checkBoxColumn.Name = " IsChecked ";
checkBoxColumn.Width = 100;
checkBoxColumn.IsVisible = true;
checkBoxColumn.DataType = typeof(string);
checkBoxColumn.DataTypeConverter = new ToggleStateConverter();
 
this.rndGridView1.Columns[0].IsVisible = false;
this.rndGridView1.Columns.Insert(0, checkBoxColumn);

There is initialization logic that is performed when a column is added to RadGridView. This is why you have to add the column and cannot assign it. You should also set the FieldName property of the column so it will know from which property of the data source it will get the data.

Please have in mind that support threads are handled according to the license type and time of posting, so if it is an urgent issue, we suggest that you use a support ticket, which would be handled before a forum thread.

I hope this will be useful. Should you have further questions, I would be glad to help.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Jeongmin
Top achievements
Rank 1
answered on 13 Aug 2013, 07:19 AM

Thank you for your answer. But Your code sample does not work properly.
CheckBox column is Added . but When Data is 'Y'  CheckBox Column not Check.
Still  ToggleStateConverter any method not called. 
I inserted CheckBox column ( not assigned) .
Do you give the complete code sample ?

   DataSet dsColumn = this.GetColumnList();

   this.gridColumn.AutoGenerateColumns = true;
   this.gridColumn.DataSource = dsColumn.Tables[0];

   var checkBoxColumn = new GridViewCheckBoxColumn
                {
                    HeaderText = " GRID_VISIBLE_YN ",
                    FieldName = " GRID_VISIBLE_YN ",
                    Name = " GRID_VISIBLE_YN ",
                    Width = 100,
                    IsVisible = true,
                    DataType = typeof (string),
                    DataTypeConverter = new ToggleStateConverter()
                };

   this.gridColumn.Columns.Insert(0, checkBoxColumn);


0
Accepted
Ivan Petrov
Telerik team
answered on 15 Aug 2013, 03:46 PM
Hi Jeongmin,

Thank you for writing back.

I have attached an example where I have copied the converter from our help article. The only difference is that I modified it so it would work with strings rather than characters. I bind the grid view to a DataTable with a string column and show the values form that column in the grid check box column.

One thing I noticed in your code is that you have an empty spaces around the field name of the column:
" GRID_VISIBLE_YN ". This would make the field name invalid and will cause the column to not work correctly. I would suggest you remove this spaces and try your project again.

I hope this helps. Do not hesitate to write back with further questions.

Regards,
Ivan Petrov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Jeongmin
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Jeongmin
Top achievements
Rank 1
Share this question
or