Column text for moved column

Posted by: arowland on 14 February 2021, 9:10 pm EST

    • Post Options:
    • Link

    Posted 14 February 2021, 9:10 pm EST

    Can you help me please with the relevant code to obtain the correct text value for a column once that column has been moved by the user. When i use the following code I get the value for the column where the column was prior to its move:

    grid.Columns(grid.Col).CellValue(grid.Row)

    Thanks

    Andy

  • Posted 14 February 2021, 9:16 pm EST

    Apologies using the C1TrueDBGrid

  • Posted 14 February 2021, 10:41 pm EST

    Hi,

    You can use the column’s name instead of its index to access the column to make sure that you are getting the data from the specific column even after the order of the columns has been changed.

    C1TrueDBGrid1.Columns("Cost").CellValue(2)
    

    Please refer to the sample attached. If you have any questions, please let us know.

    Regards.

    Avnish.

    TDBColMove.zip

  • Posted 14 February 2021, 10:47 pm EST

    My scenario is as follows.

    Grid displayed, user moves one or more columns.

    User accesses context menu to copy contents of the current caretted column.

    Would not know the column name in this instance.

    How do I read the contents of the current cell?

    Regards

    Andy

  • Posted 14 February 2021, 11:33 pm EST

    Hi Andy,

    Thank you for providing the details about your use case. You can use the Row and Col property of the TrueDBGrid to get the row and column of the current cell, then you can use these indexes to get the value of the current cell.

    C1TrueDBGrid1(C1TrueDBGrid1.Row, C1TrueDBGrid1.Col)
    

    Please refer to the sample attached. If you have any questions, please let us know.

    Regards.

    Avnish.

    TDBColMove_mod1.zip

  • Posted 15 February 2021, 12:19 am EST - Updated 3 October 2022, 2:23 pm EST

    Thanks for your example. Unfortunately does the same as my example.

    If you move a column then get data - you don’t get the value from the moved column.

    Move Qt column and get data from Qt first value you get ‘Doe Enterprises’.

    Regards

    Andy

  • Posted 15 February 2021, 3:24 pm EST

    Hi Andy,

    When the columns are moved, only the display columns of the split are moved and not the C1DataColumn. You can get the data from the current cell even after a column is moved, by using the Col property to get the index of the current column and then use this index to get the corresponding display column. Once you have the display column, you can use its DataColumn property to get the C1DataColumn associated with it and then using the CellValue method of the C1DataColumn, get the data of the cell. Please refer to the sample attached.

    Regards.

    Avnish

    TDBColMove_mod2.zip

  • Posted 15 February 2021, 7:08 pm EST

    Thanks that works a treat.

    Regards

    Andy

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels