Q: Scroll to a Row?

Discussion in 'ASP .Net Datagrid Control' started by Soul, Sep 6, 2003.

  1. Soul

    Soul Guest

    Hi,

    I have DataGrid on a C# Windows Application. Can I know how can I scroll to
    a particular row in the DataGrid?

    Thank you.

    --
    Soul
     
    Soul, Sep 6, 2003
    #1
    1. Advertising

  2. "Soul" <> wrote in message news:<>...
    > Hi,
    >
    > I have DataGrid on a C# Windows Application. Can I know how can I scroll to
    > a particular row in the DataGrid?
    >
    > Thank you.



    Hi Soul
    FYI this is the group for ASP.NET datagrid and not for Windows Forms.
    However here is my answer to your question:

    You have to use the concept of the CurrencyManager in windows forms.
    Then you can scroll to a specific row by aasigning the appropriate value
    to the Position property of the CurrencyManager object.

    Lets say that you bind DataTable dt to a Datagrid dataGrd. Then

    you have :

    DataGrd.DataSource = dt;
    cm = (CurrencyManager)this.BindingContext[dt];
    cm.Position = 2; // scrolls to the second row of the datagrid

    I include the full code below:

    On the Load event of your form populate the datagrid see below

    private void DatagridBinding_Load(object sender, System.EventArgs e)
    {
    // Create a Datatable to bind it to the Datagrid

    DataTable dt = new DataTable();

    DataColumn dc = new DataColumn("FirstName",System.Type.GetType("System.String"));
    dt.Columns.Add(dc);
    dc = new DataColumn("LastName",System.Type.GetType("System.String"));
    dt.Columns.Add(dc);

    DataRow dr = dt.NewRow();
    dr["FirstName"] = "Donald";
    dr["LastName"] = "Knuth";
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr["FirstName"] = "Richard";
    dr["LastName"] = "Karp";
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr["FirstName"] = "Jim";
    dr["LastName"] = "Gray";
    dt.Rows.Add(dr);


    DataGrd.DataSource = dt;
    cm = (CurrencyManager)this.BindingContext[dt];
    cm.Position = 0;
    }

    and then you can scroll to row 1 by cm.Position = 1 etc.

    Regards

    Lefteris
     
    Elefterios Melissaratos, Sep 7, 2003
    #2
    1. Advertising

  3. Soul

    Soul Guest

    Thanks, it work

    --
    Soul


    "Elefterios Melissaratos" <> wrote in message
    news:...
    | "Soul" <> wrote in message
    news:<>...
    |
    | [Snipped]
    |
     
    Soul, Sep 7, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nicholas
    Replies:
    0
    Views:
    446
    nicholas
    Dec 7, 2004
  2. Kevin
    Replies:
    1
    Views:
    9,575
    Roland
    Feb 5, 2005
  3. Sathiamoorthy

    Enable Scroll up and scroll down in CR-report

    Sathiamoorthy, Nov 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    910
    zobalee
    Nov 28, 2006
  4. UJ
    Replies:
    1
    Views:
    602
    John Timney \(MVP\)
    Nov 1, 2006
  5. D
    Replies:
    0
    Views:
    229
Loading...

Share This Page