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

GridView like Excel

3 Answers 106 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Saif
Top achievements
Rank 2
Saif asked on 28 May 2014, 02:14 PM
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.

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 02 Jun 2014, 07:15 AM
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.
 
0
Saif
Top achievements
Rank 2
answered on 21 Jun 2014, 09:39 AM
Hi Desislava,

This works 100%
Thank you so much.

Which event should i use when user click the arrow on scrollbar?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Jun 2014, 12:44 PM
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.
 
Tags
GridView
Asked by
Saif
Top achievements
Rank 2
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Saif
Top achievements
Rank 2
Share this question
or