Column resize on automatic updated radgridview issue

2 posts, 0 answers
  1. Ziblib
    Ziblib avatar
    1 posts
    Member since:
    Feb 2016

    Posted 14 Feb Link to this post

    Hi,

     I have a form with a radGridView (with 4 columns), the radGridView datasource is a datatable which i update every one second.

    When i try to resize any column the width is being reset instead of stretching according to the mouse position.

     

    Here is the test application code :

     

    Random rndRandom = new Random();

    private void RadForm1_Load(object sender, EventArgs e)
    {
        radGridView1.AutoGenerateColumns = false;

        timer1.Start();
    }



    private void timer1_Tick(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("AAA1", typeof(int));
        dt.Columns.Add("AAA2", typeof(int));
        dt.Columns.Add("AAA3", typeof(int));
        dt.Columns.Add("AAA4", typeof(int));

        for (int i = 0; i < 20; i++)
        {
            DataRow dr = dt.NewRow();

            dr["AAA1"] = rndRandom.Next();
            dr["AAA2"] = rndRandom.Next();
            dr["AAA3"] = rndRandom.Next();
            dr["AAA4"] = rndRandom.Next();

            dt.Rows.Add(dr);
        }

        radGridView1.DataSource = dt;
    }

     

    Is there anyway to sort this issue?

  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 18 Feb Link to this post

    Hello Ziblib,

    Thank you for writing.
     
    This scenario can't be considered as valid because when you change the RadGridView.DataSource, the whole grid is refreshed in order to display the new data. If a resize operation is ongoing when the timer ticks, you can encounter an invalid state for the grid. That is why I would recommend you skip the DataSource reset when the resize cursor is applied to the grid:
    private void timer1_Tick(object sender, EventArgs e)
    {
        if (this.radGridView1.Cursor != Cursors.SizeWE)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("AAA1", typeof(int));
            dt.Columns.Add("AAA2", typeof(int));
            dt.Columns.Add("AAA3", typeof(int));
            dt.Columns.Add("AAA4", typeof(int));
     
            for (int i = 0; i < 20; i++)
            {
                DataRow dr = dt.NewRow();
     
                dr["AAA1"] = rndRandom.Next();
                dr["AAA2"] = rndRandom.Next();
                dr["AAA3"] = rndRandom.Next();
                dr["AAA4"] = rndRandom.Next();
     
                dt.Rows.Add(dr);
            }
     
            radGridView1.DataSource = dt; 
        }
    }

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top