Selecting ListViewRows which are not visible at the moment.

Mar 19, 2009 at 1:02 AM
Hello. 
I have a DataGrid, I go through rows and pick some to select them in future. But it looks like not all rows are visible (vertical scroll is present) and listViewRow.Select() is trying to access to row somewhere out of bounds.
What is the best approach to select ListViewRow which is not visible at the moment? 
Thanks.
Mar 19, 2009 at 3:17 AM

if the row, which you need to select is not visible, then an exception will be thrown. Either you can check for IsRowVisible everytime you loop through the rows and do a Scroll if not visible, or you can use the method below which works well for me.
Try this,

        public static void ClickListViewUsingColumnValue(ListView lv, String columnName, String columnValue)
        {
            int rowIndex = GetListViewRowIndexUsingColumnValue(lv, columnName, columnValue);
            lv.Cell(columnName, rowIndex).Click();
        }



        public static int GetListViewRowIndexUsingColumnValue(ListView lv, String columnName, String columnValue)
        {
            int RowCnt = lv.Rows.Count;
            if (RowCnt > 0)
            {
                for (int Icount = 0; Icount < RowCnt; Icount++)
                {
                    string strColumnValue = ListViewUtils.GetListViewItemByColumnName(lv, Icount, columnName).Current.Name;
                   
                    if (string.Compare(columnValue.Trim(), strColumnValue.Trim(), false) == 0)
                    {
                        return Icount;
                    }
                }
            }
            return -1;
        }
Mar 20, 2009 at 1:46 PM
Thank you for reply! Got the idea and applied it.