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

Get value of RadCheckBoxElement in radGridview

2 Answers 143 Views
GridView
This is a migrated thread and some comments may be shown as answers.
kenny
Top achievements
Rank 1
kenny asked on 24 Sep 2010, 03:56 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using System.Collections;
using Telerik.WinControls;

namespace Test_POW
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        bool isCheck = false;
        int z = 0;
        ArrayList arrControl = new ArrayList();

        string[] strArr = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", };

        private void load()
        {
            DataTable data = new DataTable();
            data.Columns.Add("1");
            data.Columns.Add("2");
            data.Columns.Add("3");
            data.Columns.Add("4");
            data.Columns.Add("5");

            for (int i = 0; i < strArr.Length; i++ )
            {
                DataRow dr = data.NewRow();
                dr[0] = "";
                dr[1] = "";
                dr[2] = "";
                dr[3] = "";
                dr[4] = "";
                data.Rows.InsertAt(dr, 0);
            }


            radGridView1.DataSource = data;

            radGridView1.Columns[0].Width = 100;
            radGridView1.Columns[1].Width = 100;
            radGridView1.Columns[2].Width = 100;
            radGridView1.Columns[3].Width = 100;
            radGridView1.Columns[4].Width = 100;


        }

        private void Form1_Load(object sender, EventArgs e)
        {
            load();
        }

        private void btnAlert_Click(object sender, EventArgs e)
        {

            for (int i = 0; i < radGridView1.RowCount; i++)
            {
                for (int j = 0; j < radGridView1.ColumnCount; j++)
                {
                    radGridView1.Rows[i].IsCurrent = true;
                    radGridView1.Columns[j].IsCurrent = true;
                    if (radGridView1.CurrentColumn.Index == j && radGridView1.CurrentRow.Index == i)
                    {
                        RadCheckBoxElement check = new RadCheckBoxElement();
                        while (z < strArr.Length)
                        {
                            check.Name = "check_" + strArr[z];
                            check.Text = strArr[z];
                            arrControl.Add("check_" + strArr[z]);
                       
                            radGridView1.CurrentCell.Children.Add(check);
                            z++;
                            break;
                        }
                    }
                    if (z == 5)
                    {
                        break;
                    }
                    if (z == strArr.Length)
                    {
                        break;
                    }

                }
                if (z == strArr.Length)
                {
                    break;
                }
            }
            radGridView1.Rows[0].IsCurrent = true;
            radGridView1.Columns[0].IsCurrent = true;
        }

        private void btnGetCheckBox_Click(object sender, EventArgs e)
        {
            I want when checked in that RadCheckBoxElements and Click Button (btnGetCheckBox_Click) will
            get value (true,false) of RadCheckBoxElement checked

        }
    }
}


Help me!

Thank you!

2 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 24 Sep 2010, 05:37 AM
Hello kenny,

If you want to go again through all of the checkbox elements in all rows and all the columns and get their value you can just do what you did to create them, something like this
private void btnGetCheckBox_Click(object sender, EventArgs e)
{
    for (int i = 0; i < radGridView1.RowCount; i++)
    {
        for (int j = 0; j < radGridView1.ColumnCount; j++)
        {
            radGridView1.Rows[i].IsCurrent = true;
            radGridView1.Columns[j].IsCurrent = true;
            if (radGridView1.CurrentColumn.Index == j && radGridView1.CurrentRow.Index == i && radGridView1.CurrentCell.Children.Count != 0)
            {
                var check = (RadCheckBoxElement)radGridView1.CurrentCell.Children[0];
                switch (check.ToggleState)
                {
                    case ToggleState.On:
                        // do something
                        break;
                    case ToggleState.Off:
                        // do something else
                        break;
                }
            }
        }
    }
}

This should do what you want,

By the way, if your only goal here is to add some custom controls to a cell you should check out this article

Best Regards,
Emanuel Varga
0
kenny
Top achievements
Rank 1
answered on 24 Sep 2010, 08:24 AM
Thank you!
Tags
GridView
Asked by
kenny
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
kenny
Top achievements
Rank 1
Share this question
or