Completed
Last Updated: 27 Oct 2015 15:33 by ADMIN
ADMIN
Dimitar
Created on: 14 Sep 2015 10:14
Category: GridView
Type: Bug Report
1
FIX. RadGridView - the Discrete scroll mode is not working with columns.
To reproduce:
 radGridView1.TableElement.ColumnScroller.ScrollMode = ItemScrollerScrollModes.Discrete;

Workaround:

radGridView1.TableElement.HScrollBar.MouseUp += RadGridView1_HScrollBarMouseUp;

private void RadGridView1_HScrollBarMouseUp(object sender, MouseEventArgs e)
{
    int ixCol = GetLeftCol(radGridView1);
    Debug.WriteLine( "Index = "+ ixCol);
    if (ixCol > -1)
    {
        radGridView1.TableElement.ScrollToColumn(ixCol);
        radGridView1.Rows[0].Cells[ixCol].EnsureVisible();
    }
}

private int currentLeftColumnIndex = 0;
private int lastScrollPos = 0;
public int GetLeftCol(RadGridView grd)
{
    try
    {

        if (!grd.Columns.Any())
            return -1;
        if (!grd.TableElement.VisualRows.Any())
            return -1;
        if (grd.TableElement.ColumnScroller.Scrollbar.Value == 0)
            return -1;

        GridRowElement firstVisualRow = grd.TableElement.VisualRows.Where(r => r is Telerik.WinControls.UI.GridDataRowElement).First();
        GridCellElement firstVisualCell = firstVisualRow.VisualCells.Where(c => c is Telerik.WinControls.UI.GridDataCellElement).First();
        GridCellElement lastVisualCell = firstVisualRow.VisualCells.Where(c => c is Telerik.WinControls.UI.GridDataCellElement).Last();

        if (grd.TableElement.ColumnScroller.Scrollbar.Value > lastScrollPos)
        {
            //"Scrolling Right"
            if (lastVisualCell.ColumnIndex == grd.Columns.Last().Index)
            {
                lastScrollPos = grd.TableElement.ColumnScroller.Scrollbar.Value;
                return -1;
            }
            if (currentLeftColumnIndex == firstVisualCell.ColumnIndex)
            {
                currentLeftColumnIndex += 1;
            }
            else
            {
                currentLeftColumnIndex = firstVisualCell.ColumnIndex < grd.Columns.Count ? firstVisualCell.ColumnIndex : grd.Columns.Count - 1;
            }
            lastScrollPos = grd.TableElement.ColumnScroller.Scrollbar.Value + 1;
        }
        else
        {
            currentLeftColumnIndex = firstVisualCell.ColumnIndex;
            lastScrollPos = grd.TableElement.ColumnScroller.Scrollbar.Value - 1;
        }

        return currentLeftColumnIndex;
    }
    catch (Exception ex)
    {
        return -1;
    }
}
0 comments