GridView like Excel

4 posts, 0 answers
  1. Saif
    Saif  avatar
    30 posts
    Member since:
    Apr 2014

    Posted 28 May 2014 Link to this post

    Hi,

    I'm creating a GridView like MS Excel.
    If the user reach the last row and press arrow down it will add new row.
    And also i want to apply this add new row on Scrolling.
    I'd appreciate if you can help.
    Thanks.
  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 02 Jun 2014 Link to this post

    Hello Saif,

    Thank you for writing.

    It is possible to achieve your requirement by subscribing to the RadGridView.MouseWheel event, where you should add a new row if the vertical scroll bar is at the bottom. As to the down arrow key, the RadGridView.PreviewKeyDown event is appropriate for handling this case:  
    public Form1()
    {
        InitializeComponent();
     
        this.radGridView1.ViewCellFormatting += radGridView1_ViewCellFormatting;
        this.radGridView1.MouseWheel += radGridView1_MouseWheel;
        this.radGridView1.PreviewKeyDown += radGridView1_PreviewKeyDown;
     
        for (int i = 0; i < 20; i++)
        {
            this.radGridView1.Rows.Add(i, i + ".Data", DateTime.Now.AddDays(i));
        }
    }
     
    private void radGridView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
    {
        if (e.KeyCode == Keys.Down &&
            radGridView1.TableElement.VScrollBar.Value >= radGridView1.TableElement.VScrollBar.Maximum -
            radGridView1.TableElement.VScrollBar.LargeChange && radGridView1.CurrentRow != null &&
            radGridView1.GridNavigator.IsLastRow(radGridView1.CurrentRow))
        {
            this.radGridView1.Rows.AddNew();
        }
    }
     
    private void radGridView1_MouseWheel(object sender, MouseEventArgs e)
    {
        if (radGridView1.TableElement.VScrollBar.Value >= radGridView1.TableElement.VScrollBar.Maximum -
            radGridView1.TableElement.VScrollBar.LargeChange)
        {
            this.radGridView1.Rows.AddNew();
        }
    }
     
    //this is used only to display a row number in the row header
    private void radGridView1_ViewCellFormatting(object sender,
        Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        if (e.CellElement is GridRowHeaderCellElement)
        {
            if (e.Row is GridViewDataRowInfo)
            {
                e.CellElement.Text = (e.CellElement.RowIndex + 1).ToString();
            }
        }
    }

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Saif
    Saif  avatar
    30 posts
    Member since:
    Apr 2014

    Posted 21 Jun 2014 Link to this post

    Hi Desislava,

    This works 100%
    Thank you so much.

    Which event should i use when user click the arrow on scrollbar?
  5. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 25 Jun 2014 Link to this post

    Hello Saif,

    Thank you for writing back.

    You can use the RadGridView.TableElement.VScrollBar.SecondButton.MouseDown event to handle the case when the user clicks over the bottom arrow of the vertical scroll bar.

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top