We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do you find out which rows of a DataGrid are visible?

Thread ID:





229 May 6,2002 01:32 PM UTC May 6,2002 03:30 PM UTC WinForms 2
Tags: FAQ
James Moore
Asked On May 6, 2002 01:32 PM UTC

How do you find out which rows of a DataGrid are visible? There's FirstVisibleColumn and Visible{Column,Row}Count properties, but strangely enough there's no corresponding FirstVisibleRow. Am I missing something basic here?

Clay Burch [Syncfusion]
Replied On May 6, 2002 03:28 PM UTC

In a Windows Forms DataGrid, I don't think there is a property exposed that handles this. But here is little trick that will allow you to get the top-left visible cell. 1) Add a private member Point pointInCell00 to the form containing the datagrid. 2) After the datagrid has been initialized, but before your user has been able to scroll it (say at the end of the Form_Load event), use code such as this to initialize midPointCell00 to be a point in cell 0,0. pointInCell00 = new Point(dataGrid1.GetCellBounds(0,0).X + 4, dataGrid1.GetCellBounds(0,0).Y + 4); 3) Then add this method to return DataGridCell that is the top-left cell. public DataGridCell TopLeftVisibleCell() { DataGrid.HitTestInfo hti = dataGrid1.HitTest(this.midPointCell00); return new DataGridCell(hti.Row, hti.Column); } private void button1_Click(object sender, System.EventArgs e) { MessageBox.Show(TopLeftVisibleCell().RowNumber.ToString() + " " + TopLeftVisibleCell().ColumnNumber.ToString()); }

Clay Burch [Syncfusion]
Replied On May 6, 2002 03:30 PM UTC

In my previous post, please change all midPointCell00's to pointInCell00's.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon