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

Constant using DataSource

8 Answers 109 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Galileon
Top achievements
Rank 1
Galileon asked on 18 Nov 2008, 06:50 PM
Hi,
I need to make this working:

GridView - binded to Collecion
In some interval ex: 1 second data is changing in collecion for example ( order_status )
it is  working - grid is updating necessary cells but when i set the grouping for this column ( order_status )
the situation is not soo good - items stays in previous order_status group. ( ex. 'Payment Arrive' )
I have pass this by updating grid via setting DataSource to changed collection and then it is woking but in this case
i cant do any operation like column reorder, drag column to grouping panel becouse in this interval ( one second ) list going to update
and i cant do this

Is there any good solution to make this working?

8 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 21 Nov 2008, 04:38 PM
Hi Galileon,

Thank you for writing.

I am not sure whether I understand your scenario in detail, because I do not know what kind of collections you are using. I have created an example project that demonstrates how RadGridView performs with applied grouping when changing data in bound custom object.

You could find the example as attachment to this message. I hope it will be useful for you.
 
Do not hesitate to contact me again if you have any additional questions.

Sincerely yours,
Martin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Galileon
Top achievements
Rank 1
answered on 21 Nov 2008, 06:04 PM
Hi,
Thank You for reply and sample App - now i see that dataBinding is wrong
Below You cann see changed Your code to DataTable binding
and there is You can please tell me that is possible to do this in this convient like below
i am looking for some good solution but when i am binding content to DataTable and then call rows.Clear
gris i refreshing all data - is possible to store dararows keys and update the grid withour refreshing all data?
I am sorry but me english is poor as You see - you can replace cs code in Your example and then this should be more clear.
Onece again thank You for Your help.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CustomObjectDS
{
    public partial class Form1 : Form
    {
        
        private DataTable test_table = new DataTable();
        private int counter = 0;
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        
            test_table.Columns.Add("Index");
            test_table.Columns.Add("Content");
            test_table.Rows.Add("1","MARIAN");
            test_table.Rows.Add("1333","MARIAN");
            test_table.PrimaryKey = new DataColumn[]  {test_table.Columns[0]};
            this.radGridView1.DataSource = test_table;// this.customColection;
            this.radGridView1.Columns[0].Width = 200;
            this.radGridView1.Columns[1].Width = 200;
            this.timer1.Enabled = true;

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.ChangeData();
        }

        private void ChangeData()
        {

            counter++;

            this.radGridView1.SuspendUpdate();
            test_table.Rows.Clear();
            test_table.Rows.Add("1", "MARIAN");
            test_table.Rows.Add("1333", "MARIAN");
            test_table.Rows[0][0] = counter.ToString();
            this.radGridView1.ResumeUpdate();
            //this.radGridView1.GridElement.Update(Telerik.WinControls.UI.GridUINotifyAction.RowsChanged);
        }
    }
}
0
Bahram Moinvaziri
Top achievements
Rank 1
answered on 21 Nov 2008, 09:16 PM
Hi,
I have a dataset with two unrelated tables. After looking at this example, do i need to assign the DataSet to a bindinglist to make both tables to show up in my gridview?
thanks,
Bahram
0
Martin Vasilev
Telerik team
answered on 25 Nov 2008, 03:35 PM
Rafal, you do not need to clear and add again the data to refresh the grid. If you have troubles with refreshing, you could use the Update method of the GridElement. Check the following code for the ChangeData method when using a DataTable as data source:
 
private void ChangeData() 
    counter++; 
    test_table.Rows[0][0] = counter.ToString(); 
 this.radGridView1.GridElement.Update(Telerik.WinControls.UI.GridUINotifyAction.RowsChanged); 

 
Bahram, to present two tables in RadGridView you have to arrange a relation between them. Please review our Tutorial for Binding to Hierarchical Data.

If you have additional questions, do not hesitate to contact me again.

 
Best wishes,
Martin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Galileon
Top achievements
Rank 1
answered on 25 Nov 2008, 04:28 PM
hi,
Thank You for Your replay - and this is fine but try to set grouping then updaterows
groups are not going to change and this is the clue

Regards
Rafal
0
Galileon
Top achievements
Rank 1
answered on 25 Nov 2008, 04:39 PM
Once Again ;)

My custom Object Collecion -> Retrieving From database in some interval;
For example:

class Order
{
  int id {}
  int status {}
}

retrieving via SELECT * FROM orders_table

for each select statment i am clearing collecion ArrayList.RemoveAll ();

and here is the main problem - items are refreshing at all
and even  this.radGridView1.GridElement.Update(Telerik.WinControls.UI.GridUINotifyAction.RowsChanged);
 update is going all the data at the grid




0
Galileon
Top achievements
Rank 1
answered on 25 Nov 2008, 05:13 PM
Hi Again
please replace Form1.cs code of Your example to
and you can see what is exacly my problem - grouping is not changing

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CustomObjectDS
{
    public partial class Form1 : Form
    {
        private List<OrderItem> orders = new List<OrderItem>();
        int counter = 0;
        
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            orders.Add(new OrderItem(1, 1));
            orders.Add(new OrderItem(2, 1));
            orders.Add(new OrderItem(3, 2));
            orders.Add(new OrderItem(4, 2));

            this.radGridView1.DataSource = orders;
            this.radGridView1.Columns[0].Width = 200;
            this.radGridView1.Columns[1].Width = 200;

            this.radGridView1.MasterGridViewTemplate.GroupByExpressions.Add("[Status] Group by [Status]");
            this.radGridView1.MasterGridViewTemplate.AutoExpandGroups = true;

            this.timer1.Enabled = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.ChangeData();
        }

        private void ChangeData()
        {
            counter++;

            if (counter > 5)
            {
                orders[3].Status = 3;
                orders[3].Desc = "Modified";
            }

            this.radGridView1.GridElement.Update(Telerik.WinControls.UI.GridUINotifyAction.RowsChanged);
        }


        public class OrderItem
        {
            public OrderItem (int id, int status)
            {
                this._id = id;
                this._status  = status;
            }

            private int _id;
            private string _desc;

            public string Desc
            {
                get { return _desc; }
                set { _desc = value; }
            }

            public int Id
            {
                get { return _id; }
                set { _id = value; }
            }
            private int _status;

            public int Status
            {
                get { return _status; }
                set { _status = value; }
            }

        }

    }
}
0
Accepted
Martin Vasilev
Telerik team
answered on 28 Nov 2008, 08:22 AM
Hi Galileon,

Thank you for contacting me again.

From your code the RadGridView does not refresh, because the List<T> class does not provide backward notification if data change occurs. If you want to use a custom object as your DataSource it has to  implemented IBindingList interface if you want two-way data-binding. The BindingList<T> already implements IBindingList and supports other rich binding scenarios. That is the reason I have used BindingList<T> in my example. 

Please, find more on the topic in the MSDN library and in the our help documentation.

Contact me again, if you need additional assistance.

Regards,
Martin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Galileon
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Galileon
Top achievements
Rank 1
Bahram Moinvaziri
Top achievements
Rank 1
Share this question
or