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

Reset gridview

7 Answers 526 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Somnath
Top achievements
Rank 1
Somnath asked on 31 Jan 2011, 03:28 PM
HI,

In my application,I have one GridView With 4 gridviewcomboboxcolumns(with Different Binding Source)...
It is possible to Cancle All changes made by user in single click....
And the restore gridview at starting position...?

Thank You

7 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 31 Jan 2011, 03:41 PM
Hello,

As long as you haven't updated your datasource, then just set the datasource to null, and then back to your datasource again. I think that would do what you want.
Hope that helps
Richard
0
Somnath
Top achievements
Rank 1
answered on 31 Jan 2011, 03:55 PM
Hello,
Actually,Your Solution does not work for me,,
Have Any other Solution.....???

Thank You
0
Richard Slade
Top achievements
Rank 2
answered on 31 Jan 2011, 03:58 PM
Hello,

If you can post a simple example of what you are currently doing, I'll be happy to take a look to help provide a solution if possible.
Look forward to hearing back from you
Richard
0
Somnath
Top achievements
Rank 1
answered on 31 Jan 2011, 04:13 PM
Hello

Here I have a Radgridview with Binding Source..

this

 

 

.Gvtemplate.DataSource = this.jETemplateEntryBindingSource;
with gridviewcomboboxcolumns

 

gridViewComboBoxColumn1.DataSource =

 

this.qbfilesBindingSource;

 

gridViewComboBoxColumn2.DataSource =

 

this.accSelectionBindingSource;
....
I used following code but it doesn't work for me

 

 

 

private void btnRefreshTemp_Click(object sender, EventArgs e)

 

{

 

 

this.Gvtemplate.DataSource = null;
this.Gvtemplate.DataSource = this.jETemplateEntryBindingSource;
}

 

 

 

 

 

 

 

0
Richard Slade
Top achievements
Rank 2
answered on 01 Feb 2011, 01:34 AM
Hello,

Here is a sample for you that resets the list and rebinds the grid. If you have any questions, please let me know

Designer File
namespace RadGridView_ResetSource_C
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components;
  
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
  
        #region Windows Form Designer generated code
  
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.radButton1 = new Telerik.WinControls.UI.RadButton();
            this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
            ((System.ComponentModel.ISupportInitialize)(this.radButton1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
            this.SuspendLayout();
            // 
            // radButton1
            // 
            this.radButton1.Location = new System.Drawing.Point(245, 311);
            this.radButton1.Name = "radButton1";
            this.radButton1.Size = new System.Drawing.Size(130, 24);
            this.radButton1.TabIndex = 0;
            this.radButton1.Text = "Reset";
            this.radButton1.Click += new System.EventHandler(this.radButton1_Click);
            // 
            // radGridView1
            // 
            this.radGridView1.Location = new System.Drawing.Point(13, 13);
            this.radGridView1.Name = "radGridView1";
            this.radGridView1.Size = new System.Drawing.Size(362, 292);
            this.radGridView1.TabIndex = 1;
            this.radGridView1.Text = "radGridView1";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(387, 347);
            this.Controls.Add(this.radGridView1);
            this.Controls.Add(this.radButton1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.radButton1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
            this.ResumeLayout(false);
  
        }
  
        #endregion
  
        private Telerik.WinControls.UI.RadButton radButton1;
        private Telerik.WinControls.UI.RadGridView radGridView1;
    }
}


form1.cs
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;
  
namespace RadGridView_ResetSource_C
{
    public partial class Form1 : Form
    {
        BindingSource m_GridBindingSource = new BindingSource();
        List<MyObject> m_MyList = new List<MyObject>();
        private List<MyObject> m_Original = new List<MyObject>();
  
        public Form1()
        {
            InitializeComponent();
        }
  
  
        private void Form1_Load(object sender, EventArgs e)
        {
            // Add colomns
            this.radGridView1.AutoGenerateColumns = false;
  
            this.radGridView1.Columns.Add(new GridViewComboBoxColumn("MyString1"));
            this.radGridView1.Columns.Add(new GridViewComboBoxColumn("MyString2"));
  
            // Binding Source For Column 1
            BindingSource source1 = new BindingSource();
            List<String> s1List = new List<String>();
            String s1a = "First (S1)";
            String s2a = "Second (S1)";
            String s3a = "Third (S1)";
            s1List.Add(s1a);
            s1List.Add(s2a);
            s1List.Add(s3a);
            source1.DataSource = s1List;
  
            // Binding Source for Column 2
            BindingSource source2 = new BindingSource();
            List<String> s2List = new List<String>();
            String s1b = "First (S2)";
            String s2b = "Second (S2)";
            String s3b = "Third (S2)";
            s2List.Add(s1b);
            s2List.Add(s2b);
            s2List.Add(s3b);
            source2.DataSource = s2List;
  
            // Set Column Data Sources
            ((GridViewComboBoxColumn)this.radGridView1.Columns["MyString1"]).DataSource = source1;
            ((GridViewComboBoxColumn)this.radGridView1.Columns["MyString2"]).DataSource = source2;
  
            // Set Grid DataSource
            PopulateList();
  
            m_GridBindingSource.DataSource = m_MyList;
            this.radGridView1.DataSource = m_GridBindingSource;
  
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        }
  
        private void PopulateList()
        {
            m_MyList.Clear();
            m_MyList.Add(new MyObject("First (S1)", "First (S2)"));
            m_MyList.Add(new MyObject("Third (S1)", "Third (S2)"));
        }
  
        private void radButton1_Click(object sender, EventArgs e)
        {
            this.radGridView1.BeginUpdate();
            this.radGridView1.DataSource = null;
            PopulateList();
            this.radGridView1.DataSource = m_GridBindingSource;
            this.radGridView1.EndUpdate();
        }
  
    }
  
  
    public class MyObject
    {
        public MyObject()
        {
        }
        public MyObject(string myString1, string myString2)
        {
            _myString1 = myString1;
            _myString2 = myString2;
        }
        private string _myString1;
        public string MyString1
        {
            get { return _myString1; }
            set { _myString1 = value; }
        }
        private string _myString2;
        public string MyString2
        {
            get { return _myString2; }
            set { _myString2 = value; }
        }
    }
}

Hope that helps
Richard
0
Somnath
Top achievements
Rank 1
answered on 01 Feb 2011, 07:14 AM
Hello,

I have a "Cancel" button on a form to cancel any changes in the
current item with the code BindingSource1.CancelEdit (gridview) but this don't
restore the older's values that had been changed.
 
Thanks For your Support
0
Richard Slade
Top achievements
Rank 2
answered on 01 Feb 2011, 11:15 AM
Hello,

I am unsure if you are still having issues with this? If so, have you tried the exmaple above? Please let me know if this helps.
Thanks
Richard
Tags
GridView
Asked by
Somnath
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Somnath
Top achievements
Rank 1
Share this question
or