Articles in this section
Category / Section

How to retrieve the cell value that is available in view only?

1 min read

You can retrieve the cell value based on the row and column indices in the GridTreeControl, by default.

C#

//Returns the cell value based on the row and column indices.
var cellValue = this.treeGrid.InternalGrid.Model[int rowIndex,int columnIndex].CellValue;

 

You can restrict and retrieve the cell value only for rows that are currently available in view by using the GetCellValue helper method.

C#

//Gets the cell value by using the GetCellValue ( ) that are currently available in the view. 
var cellvalue = GetCellValue(5, 3);

 

The GetCellValue helper method helps to decide whether the specified row and column are in the view or not by comparing the given row and column indices with the ScrollRows and ScrollColumns collections. Then the corresponding cell value is returned when the specified row and column indices are currently in the view of the GridTreeControl.

C#

String GetCellValue(int rowIndex, int columnIndex)
{            
    string currentCellValue;       
    //Gets the visible rows collection.
    var visibleRows = treeGrid.InternalGrid.ScrollRows.GetVisibleLines();
    //Gets the visible columns collection.
    var visibleColumns = treeGrid.InternalGrid.ScrollColumns.GetVisibleLines();
    //Gets the row index of the last visible line in the body region.
    int bottom = visibleRows[visibleRows.LastBodyVisibleIndex].LineIndex;
    //Gets the column index of last visible line in the body region.
    int right = visibleColumns[visibleColumns.LastBodyVisibleIndex].LineIndex;
    //Returns the cell value as a null when the row and column indices are out of view. 
    if (rowIndex > bottom || columnIndex > right )
    {
        return "Specified row and column index is in out of view ";          
    }
    //Returns the specified string when the cell value is set to null; otherwise, returns the corresponding cell value.
    if (this.treeGrid.InternalGrid.Model[rowIndex, columnIndex].CellValue == null)
    {
        return "Specified row and column index is in view but its cell value is null";
    }
    currentCellValue = this.treeGrid.InternalGrid.Model[rowIndex, columnIndex].CellValue.ToString();                                  
    return "CellValue:\t"+currentCellValue;
}

 

Sample Link:

WPF: http://www.syncfusion.com/downloads/support/directtrac/139850/ze/WPF-1899540513

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied