Forum Discussion

sbkeenan's avatar
sbkeenan
Frequent Contributor
15 years ago

Working with Dev Express XtraPivotGrid - Trying to obtain column/row headings

Hi



By using the following code, I am able to simulate a click on any cell within the pivot grid and obtain both its actual value and display value:



colCount = pgCtrl.Cells.ColumnCount

rowCount = pgCtrl.Cells.RowCount

For rows = 0 to rowCount -1

    For cols = 0 to colCount - 1

        cellW = pgCtrl.cells.GetCellInfo(cols, rows).bounds.get_Width

        cellH = pgCtrl.cells.GetCellInfo(cols, rows).bounds.get_Height

        cellL = pgCtrl.cells.GetCellInfo(cols, rows).bounds.get_Left

        CellT = pgCtrl.cells.GetCellInfo(cols, rows).bounds.get_Top

        cellX = cellL + (cellW / 2)

        CellY = cellT + (cellH / 2)

        Call pgCtrl.Click(cellX, cellY)

        cellValue = pgCtrl.GetCellValue(cols, rows)

        cellDisplay = pgCtrl.cells.GetCellInfo(cols, rows).DisplayText

        Log.Message("(" & cols & ", " & rows & "): " & cellValue & ", displayed as: " & cellDisplay)

    Next 'cols

Next 'rows



The act of clicking on each cell isn't actually necessary in order to obtain its content, I just couldn't find any other way of setting the focused cell!!



What I am trying to do now is to obtain the column and row headings for the focused cell, but am having difficulty in obtaining these.  I think the answer lies in using the native method GetFieldValue(<field as object>, <LastLevelIndex as integer>) but have had no success in using this (I don't fully understand how to specify the first parameter.)  Has anyone else come across this and have you been able to get this information?  Ideally, I am looking for a simple code snippet along the lines of:



    colHeading = pgCtrl.GetFieldValue(<whatever needs to go here>, 0)

    rowHeading = pgCtrl.GetFieldValue(<whatever needs to go here>, 0)



Any assistance would be much appreciated.



Regards

Stephen.



 

3 Replies

  • sbkeenan's avatar
    sbkeenan
    Frequent Contributor
    Hi



    I have managed to obtain the column headings by using the following:



        colHeading = pivotGrid.Cells.GetFocusedCellInfo.DataField.Caption



    I am still having difficulty in obtaining the row header.



    Any help would be greatly appreciated.



    Many thanks.



    Regards

    Stephen.

  • Hi Stephen,



    Try creating a script that obtains the focused cell's column and row indexes using members of the Grid.Cells.GetFocusedCellInfo object and then passes them as parameters of properties or methods that return the object that contains the needed text (e.g. you can check whether the Grid.Fields.Item property contains it).
  • sbkeenan's avatar
    sbkeenan
    Frequent Contributor
    Hi Jared



    I finally managed to crack the problem.



    By using:



        rowIndex = pgCtrl.Cells.GetFocusedCellInfo.RowFieldIndex

        colHeading = pgCtrl.Cells.GetFocusedCellInfo.DataField.Caption

        rowHeading = pgCtrl.Cells.GetFocusedCellInfo.Data.GetRowValue(rowIndex)



    I can get the column and row headings for the focused cell.



    I have spent a considerable amount of time on this issue, together with a couple of others, all to do with the Dev Express pivot grid control.  So, if anyone out there is interested, I have put together a document, containing some code examples that I have been able to use in my tests.  It's a Microsoft Word 2003 document, which has been zipped for the purposes of attaching it here.



    I would be happy to hear from anyone who has any comments, suggestions or better solutions!!



    Many thanks.



    Regards

    Stephen.