Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Q: Scroll to a Row?

    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 Guest

  2. Similar Questions and Discussions

    1. I want a scroll bar. I might die.
      So I've been reading through the help files and my "Flash MX2004 for Dummies" for a while now... still haven't quite got it. I have a staticframe...
    2. Scroll 2 text by one scroll bar?
      Is there anyway to scroll 2 text fields at the same time by using one scroll bar?
    3. Scroll text with scroll bar
      I've created a chunk of text and I want it to scroll in a window. Managed to put a scroll bar on it, but cannot figure out how to size the window and...
    4. Scroll help
      I don't know how to scroll texts and graphics. i mean i want to scroll them at the control of mouse (i'm not talking abt movie). Currently i'm using...
    5. scroll bar use!
      in big pages i put a scroll bar so it can fits better the text. but as i put fields and text on the text in play mode only main text moves and other...
  3. #2

    Default Re: Q: Scroll to a Row?

    "Soul" <no@spam.com> wrote in message news:<emIskxJdDHA.2860@TK2MSFTNGP11.phx.gbl>...
    > 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 Guest

  4. #3

    Default Re: Q: Scroll to a Row?

    Thanks, it work

    --
    Soul


    "Elefterios Melissaratos" <leftim@yahoo.com> wrote in message
    news:40183e.0309061653.a7fed7e@posting.google.com. ..
    | "Soul" <no@spam.com> wrote in message
    news:<emIskxJdDHA.2860@TK2MSFTNGP11.phx.gbl>...
    |
    | [Snipped]
    |

    Soul Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139