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

Chaning a cell when another changes

3 Answers 159 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ewart
Top achievements
Rank 1
ewart asked on 15 Oct 2008, 06:12 AM
Hi,  I'm using the latest version of the winform controls.  My grid has a checkbox and some text columns.

when a user clicks a checkbox in one column, I want to place a value into one of the text columns on the same row.

I've experimented with the ValueChanged and ValueChanging events but it's not obvious how to achive this from the documentation.

it's almost working but for some reason my checkboxcell value always returns nothing.. inspected it looks like {} .  The field changes in the UI quite ok, and accessing it later (via a save button on the form) in the same format gives me the correct value, but just not in the changing events?!

inspecting or setting the other columns is no problem either.

firstly, am I going about this the right way?

While i'm here I should also ask how to stop the changing events firing on demand? (when I first load the data i databind then update some fields, and I note the events firing when I programmatically update, no doubt there is an easy way to prevent this without unhooking the event handler).

if (sender is GridCheckBoxCellElement)  
{  
   GridCheckBoxCellElement g = (GridCheckBoxCellElement)sender;  
   MyObject o = (MyObject)g.RowInfo.DataBoundItem;  
   row = g.RowInfo;  
 
   if (row.Cells["checkboxcell"].Value.ToString() == "False" )  
   {  
      row.Cells["othertextcell"].Value = "";  
   }  
   else 
   {  
      row.Cells["txtKeyWord"].Value = o.myproperty;  
   }  
  
cheers
ewart

3 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 17 Oct 2008, 06:23 PM
Hello ewart,

Thank you for contacting us.

Indeed, we have an issue with getting the correct Value of the GridCheckBoxCellElement in the ValueChanged event handler. This issue will be addressed in one of our next versions.

For the time being please, get the value from the RadCheckBoxEditor of the GridCheckBoxCellElement:
 
void radGridView1_ValueChanged(object sender, EventArgs e)  
{  
    if (sender is GridCheckBoxCellElement)  
    {  
        GridCheckBoxCellElement g = (GridCheckBoxCellElement)sender;  
        RadCheckBoxEditor checkbox = g.Children[0] as RadCheckBoxEditor;  
 
        GridViewDataRowInfo row = g.RowInfo as GridViewDataRowInfo;  
        if((bool)checkbox.Value)  
        {  
            row.Cells["Bool text"].Value = "True";  
        }  
        else 
        {  
            row.Cells["Bool text"].Value = "False";  
        }  
    }    

This approach is demonstrated in the sample project attached.

As to your last question, could you please share more details about it? I would like to get more information on your scenario and the events that you do not want to fire in it. This will allow me to assist you further.

I am looking forward to your response.
 

Kind regards,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Emre Ozan Alkan
Top achievements
Rank 2
answered on 22 Oct 2009, 08:58 AM
I know it is very old topic but and many new releases released:)

but Nikolay, what is the problem with your code snippet ? how can make it work for latest versions ?

When I try to compile your sample, I get

Error    1    Cannot convert type 'Telerik.WinControls.RadElement' to 'Telerik.WinControls.UI.RadCheckBoxEditor' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion    C:\Documents and Settings\EmreAlkan\My Documents\Downloads\104018_RadGridViewCheckBoxValue\RadGridViewCheckBoxValue\RadGridViewCheckBoxValue\Form1.cs    68    46    RadGridViewCheckBoxValue
--------------------------------------------------------------------------------------------------------------------------

And is there another way to reach pure RadCheckBox element in GridCheckBoxCellElement of datagrid column, where actually we
do ;
            foreach (var row in myGrid.Rows)
            {
                if (row.Cells["IsSelectedItem"].Value != null & row.Cells["IsSelectedItem"].Value != DBNull.Value)
                {
                    if (Convert.ToBoolean(row.Cells["IsSelectedItem"].Value))
                    {

but we cannot really find the current changed/changing checkbox value. You know when I click the checkbox grid starts to edit row and show a small pencil image left of the row, however if it is newly checked or newly unchecked it still being in old state.

Actually let me say my case,
I have table  myGrid;

IsSelectedItem CustomerName CustomerSurname Payment    // are headers of grid.


and below table, there is label which is  :  Total Payment : Value

when we change checked state it should trigger and change Value of total payment, however when I first click the any row's IsSelectedItem and de select its checkbox, is it not trigger anything, there is just small pencil appear at the left of the row. I find a way to make it by Row Changed event.When we click another row it just triggered and calculate right total value of payment.


0
Nikolay
Telerik team
answered on 28 Oct 2009, 03:28 PM
Hello Emre Ozan Alkan,

Indeed, we introduced some changes in our latest releases which made the code from my previous response obsolete.

I am attaching a new version of my project which covers the latest RadGridView specifics. Please note that I am explicitly setting the Value of the CurrentCell in the ValueChanged event handler. We need to do this because the change of the 'Bool text' causes an update which resets the checkbox editor value.

I hope this helps. If you have additional questions, feel free to contact me.

Sincerely yours,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
ewart
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Emre Ozan Alkan
Top achievements
Rank 2
Share this question
or