usvpn Posted July 26, 2010 Posted July 26, 2010 Hi, I want to scroll to the first selected row in my DataGridView. You know I programmatically select a number of rows, and then want to scroll to the 1st selected row. I heard about FirstDisplayedScrollingRowIndex property but can't figure it. Anyone knows how to find the 1st selected row? and then scroll to it? Thank you :p Quote
joe_pool_is Posted August 16, 2010 Posted August 16, 2010 Here's some generic code I keep in my base form that all of my child forms inherit from: public static int GetFirstScrollingRowIndex(DataGridView dgv, string cellHeader, string cellText) { try { if ((dgv != null) && !String.IsNullOrEmpty(cellHeader) && !String.IsNullOrEmpty(cellText)) { if (dgv.Columns.Contains(cellHeader)) { for (int rowIndex = 0; rowIndex < dgv.Rows.Count; rowIndex++) { string dgvValue = dgv.Rows[rowIndex].Cells[cellHeader].Value.ToString(); if (cellText == dgvValue) { dgv.Rows[rowIndex].Selected = true; return rowIndex; } } } } } catch (Exception err) { Global.LogError(_CODEFILE + "DataGridView_", err); } return 0; } Quote Avoid Sears Home Improvement
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.