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

changing row's state

14 Answers 696 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sason
Top achievements
Rank 1
Sason asked on 18 Oct 2010, 09:19 AM
Hi,
How can i change the state of the row from unchanged to modify ?

Thank u.

14 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 18 Oct 2010, 09:21 AM
Hi Dror, 

Could you explain a little more about your situation and what you would like to achieve? 
Thanks
Richard
0
Sason
Top achievements
Rank 1
answered on 20 Oct 2010, 08:17 AM
Sory about the delay.

 

 this is my problem :

When the radgrid is populated and the user changes a cell within a row, the row is not flagged as "modified" until the user actually clicks onto another location on the datagrid. If the user modifies any values in a row and immediately clicks the "Save" button on my winform, the row is not flagged as having been modified and is not showing up in my list of modified rows.

becuse of that i whan't to change to state ( but mybe it's not a good idea).

Thank u.

 

 

0
Emanuel Varga
Top achievements
Rank 1
answered on 20 Oct 2010, 08:39 AM
Hello Dror,

You can always call radGridView1.EndEdit() on the Save button click, then you will force a CellValueChanged  / ValueChanged event to fire, (if the Save button is a command button on the grid) or it should fire automatically if the grid loses focus.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Sason
Top achievements
Rank 1
answered on 20 Oct 2010, 09:18 AM
Thank u. I'll try it.
0
Sason
Top achievements
Rank 1
answered on 20 Oct 2010, 10:22 AM
Hi

 
I try the EndEdit but it doesn't work.
my save button is not place on the grid, he outside the grid and it save all the changes that the user made.
something impotent :
its happened just when the cell is Boolean !
When the cell is text it's work great.


Dror

0
Richard Slade
Top achievements
Rank 2
answered on 20 Oct 2010, 10:34 AM
Hi 

On the row, if you call (for exmaple)
this.radGridView2.CurrentRow.InvalidateRow();

this will force a CellFormatting and ValueFormatting event. 

hope that helps
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 20 Oct 2010, 10:35 AM
hmm, apologies. That may not help you if you need ValueChanged
0
Emanuel Varga
Top achievements
Rank 1
answered on 20 Oct 2010, 10:44 AM
Hello Dror,

Please try the following example and let me know if this works for you:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using Telerik.WinControls.UI;
 
public partial class Form1 : Form
{
    private RadGridView radGridView1;
    private List<GridViewRowInfo> modifiedRows = new List<GridViewRowInfo>();
 
    public Form1()
    {
        InitializeComponent();
        this.Controls.Add(radGridView1 = new RadGridView());
        radGridView1.Size = new System.Drawing.Size(this.ClientSize.Width, this.ClientSize.Height - 24);
        radGridView1.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
        radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        radGridView1.CellValueChanged += new GridViewCellEventHandler(radGridView1_CellValueChanged);
 
        var saveButton = new RadButton();
        saveButton.Text = "Save";
        saveButton.Click += new EventHandler(saveButton_Click);
        saveButton.Dock = DockStyle.Bottom;
        this.Controls.Add(saveButton);
    }
 
    void saveButton_Click(object sender, EventArgs e)
    {
        if (this.radGridView1.IsInEditMode)
        {
            radGridView1.EndEdit();
        }
 
        MessageBox.Show("Number of modified Rows: " + modifiedRows.Count.ToString());
        modifiedRows.Clear();
    }
 
    void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
    {
        modifiedRows.Add(e.Row);
    }
 
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        radGridView1.DataSource = new TestsCollection(10);
    }
}
 
public class TestTypes
{
    public int Id
    {
        get;
        set;
    }
 
    public bool ReadOnly
    {
        get;
        set;
    }
 
    public string Name
    {
        get;
        set;
    }
}
 
public class TestsCollection : BindingList<TestTypes>
{
    public TestsCollection(int noItems)
    {
        for (int i = 0; i < noItems; i++)
        {
            this.Add(new TestTypes
                {
                    Id = i,
                    ReadOnly = i % 2 == 0 ? true : false,
                    Name = "Name" + i
                });
        }
    }
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Sason
Top achievements
Rank 1
answered on 20 Oct 2010, 11:33 AM


Hi,

Maybe I doesn't explained myself very well.

The problem is that when the user change the value of cell with Boolean type the property "ismodified" doesn't change to true ! until the user don’t set focus to anther row.

Thank u for your patience.

0
Emanuel Varga
Top achievements
Rank 1
answered on 20 Oct 2010, 11:37 AM
Can you please try my example, or make the necessary changes om my example? So that I can find a solution easier?
0
Sason
Top achievements
Rank 1
answered on 20 Oct 2010, 12:22 PM
Youe example as is work fine but my grid connect with datasource to dataset.
0
Emanuel Varga
Top achievements
Rank 1
answered on 20 Oct 2010, 12:26 PM
If you use the logic from this example you have in that list all the rows that have been changed, and you can take the data bound rows from those row infos, I hope you understand what I'm trying to say. Best regards, Emanuel Varga
0
Accepted
Alexander
Telerik team
answered on 25 Oct 2010, 02:14 PM
Hello Dror,

We have introduced an issue in the latest version of RadGridView which is related to the fact that the state of the binding source is not modified when the current row of the control is modified by code. We will address it in a next release.
 
As a workaround, please use the CellValueChanged event of RadGridView to set the state of the modified item:
private void radGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
    if (e.Row == this.radGridView1.CurrentRow)
    {
        DataRow tableRow = (this.radGridView1.CurrentRow.DataBoundItem as DataRowView).Row;
        tableRow.SetModified();
    }
}

Please let us know if this approach works in your case.

Best regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sason
Top achievements
Rank 1
answered on 28 Oct 2010, 01:40 PM
Thank u very much.

Tags
GridView
Asked by
Sason
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Sason
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or