Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Q: Scroll to a Row?

Reply
Thread Tools

Q: Scroll to a Row?

 
 
Soul
Guest
Posts: n/a
 
      09-06-2003
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



 
Reply With Quote
 
 
 
 
Elefterios Melissaratos
Guest
Posts: n/a
 
      09-07-2003
"Soul" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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
 
Reply With Quote
 
 
 
 
Soul
Guest
Posts: n/a
 
      09-07-2003
Thanks, it work

--
Soul


"Elefterios Melissaratos" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). ..
| "Soul" <(E-Mail Removed)> wrote in message
news:<(E-Mail Removed)>...
|
| [Snipped]
|

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enable Scroll up and scroll down in CR-report Sathiamoorthy ASP .Net 1 11-28-2006 11:42 PM
Listbox disabled - cant scroll in IE - can scroll in Firefox =?Utf-8?B?Ui5OaWprYW1w?= ASP .Net 0 11-22-2006 03:46 PM
Using a div with scroll bars - can we get the scroll bars on the left instead of the right side? UJ ASP .Net 1 11-01-2006 09:32 PM
change the scroll speed of a scroll pane? Kevin Java 1 02-05-2005 09:42 AM
prevent mouse scroll to scroll in a dropdownlist nicholas ASP .Net 0 12-07-2004 11:26 AM



Advertisments