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

Value of check box

4 Answers 406 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 23 Nov 2007, 07:35 PM
How do I get the value from a check box after it has been clicked?  The code below in the ValueChanged event seems to return random results.  Note that "InitialAssignee" is the column name that I happen to be clicking on.

        private void radGrid_ValueChanged(object _sender, EventArgs _e)  
        {  
            MessageBox.Show(radGrid.MasterGridViewInfo.CurrentRow.Cells["InitialAssignee"].Value.ToString(), "");  
        }  
 

Thanks.

4 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 26 Nov 2007, 03:55 PM
Hi Eric,

You can get the value exactly as you do:

    radGrid.MasterGridViewInfo.CurrentRow.Cells["InitialAssignee"].Value

It may seem that this code returns the wrong result, but in fact it returns the current value of the cell before the new value is persisted in it. The reason is that the ValueChanged event fires every time when the value of a cell's editor is changed, while the value of the cell itself remains the original. Finally, when the value is "saved" in the cell (for example when the user moves to another cell or presses Enter or something else happens), you will get the correct value. To do this, I would suggest to you to use Validated event.

If you have any additional questions, please don't hesitate to write us.
 

Regards,
Georgi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Eric
Top achievements
Rank 1
answered on 26 Nov 2007, 06:10 PM
Thanks for your response Georgi.  Because I want to know exactly when the value changes, not just when it is saved, I have put my code in the ValueChanging.  I am able to get the value from the e.NewValue property. 

Thanks,
Eric.
0
Gazzman
Top achievements
Rank 1
answered on 10 Dec 2007, 11:00 AM
        private void PopulateGrid()  
        {  
            DataTable objDt = new DataTable();  
 
            DataColumn colID = new DataColumn();  
            colID.ColumnName = "ID";  
            colID.AutoIncrement = true;  
            objDt.Columns.Add(colID);  
 
            objDt.Columns.Add("Name"typeof(string));  
            objDt.Columns.Add("Tel"typeof(string));  
            objDt.Columns.Add("Selected"typeof(bool));  
 
            DataRow dr = null;  
 
            dr = objDt.NewRow();  
            dr["Name"] = "Fred";  
            dr["Tel"] = "888 777";  
            dr["Selected"] = false;  
            objDt.Rows.Add(dr);  
 
            dr = objDt.NewRow();  
            dr["Name"] = "Jane";  
            dr["Tel"] = "123 789";  
            dr["Selected"] = false;  
            objDt.Rows.Add(dr);  
 
 
            radGridView1.DataSource = objDt;  
            radGridView1.GridElement.BeginUpdate();  
            radGridView1.MasterGridViewTemplate.AllowAddNewRow = false;  
 
            for (int x = 0; x < radGridView1.MasterGridViewTemplate.Columns.Count; x++)  
            {  
                radGridView1.MasterGridViewTemplate.Columns[x].BestFit();  
            }  
 
            radGridView1.MasterGridViewTemplate.Columns["ID"].IsVisible = false;  
 
            radGridView1.GridElement.EndUpdate();  
 
            objDt.Dispose();  
 
        }  
 
        private void bGetSelected_Click(object sender, EventArgs e)  
        {  
            label1.Text = "";  
 
            GridViewInfo gvi = radGridView1.MasterGridViewInfo;  
            GridViewRowInfo gvri = null;  
 
            for (int i = 0; i < gvi.Rows.Count; i++)  
            {  
                gvri = gvi.Rows[i];  
 
                if ((bool)gvri.Cells["Selected"].Value == true)  
                {  
                    label1.Text += gvri.Cells["ID"].Value.ToString() + ", ";  
                }  
            }  
        } 
Hi Georgi,

I was hoping you could help me please. I have a similar problem to the one described below. In essence, I would like to update a DataTable as soon as a check box is clicked. I have an ID column in my RadGridView which I wish to use to update the DataTable. The probelm I face is that I do not seem to be able to find an event I can use to capture the edited value. Is there an EndEdit / Update method I can use? i.e. Can I add a method call to a 'Save' button which would update the value of the cell without having to click another row or press enter?

Thanks!

George

0
Georgi
Telerik team
answered on 11 Dec 2007, 06:10 PM
Hello Stylli,

I have replied to your question in your other post. Here is the text:

You are on the right track - your code is accurate except that it should be executed in the ValueChanged event. I have tested your scenario and it works as you need it to. It saves the value immediately after the checkbox cell is clicked.

If you need assistance, please do not hesitate to write us again.


Regards,
Georgi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Eric
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Eric
Top achievements
Rank 1
Gazzman
Top achievements
Rank 1
Share this question
or