Clearing selection of True DBGrid

Posted by: development on 3 December 2018, 12:42 pm EST

    • Post Options:
    • Link

    Posted 3 December 2018, 12:42 pm EST

    Hi All

    I have a true dbgrid on a windows form and when it loads the first row is always selected.

    I have tried using gridName.SelectedRows.Clear() but this does not seem to work.

    Is there any way to remove the selection?

    Ideally something that works like DataGridView.ClearSelection()

    Thanks in advance for any suggestions.

  • Posted 4 December 2018, 1:48 am EST

    Hi,

    TrueDB Grid uses two styles to denote selected range (SelectionStyle), and active cell (MarqueeStyle). There is always a cell which is active so the dotted border (default MarqueeStyle) will always be shown.

    However, if you don’t want a dotted cell at the beginning then you can set MarqueeStyle to NoMarquee, and then once a cell is selected, restore the default MarqueeStyle.

    You can refer to the attached sample for the same.

    Regards,

    Jitender

    ClearSelection.zip

  • Posted 6 December 2018, 5:44 am EST

    Hi Jitender,

    So we are in agreement that the SelectedRows.Clear() has no effect?

    It seems a bit odd that there is always an active cell to me… I will have to change this form to use the standard windows DataGridView as it degrades the user experience to have something selected before they select it!

    Thanks for your time.

  • Posted 7 December 2018, 3:28 am EST

    Hi,

    As I said earlier, C1TrueDBGrid uses two styles: one for ActiveCell and one for SelectedCell; SelectedRows.Clear() clears the selected rows. In your case, you want to clear the active cell.

    Please also note that DataGridView also always has an active cell, just like TrueDBGrid.

    You can observe this if you use this code with DataGridView:

    dataGridView1.ClearSelection();
    int row = dataGridView1.CurrentCell.RowIndex;
    int col = dataGridView1.CurrentCell.ColumnIndex;
    

    You’ll see that row and col would be assigned valid indexes (since a cell is still active).

    DataGridView’s ClearSelection() method only removes the styling from the grid, until a cell is again clicked.

    You can get the same behaviour in C1TrueDBGrid if you set MarqueeStyle to NoMarquee in the beginning, and once the grid is clicked, restore the original MarqueeStyle.

    I’ve also modified the earlier sample so that it works exactly like DataGridView. There is no highlighted cell at the beginning, a cell is only highlighted once a click is performed on any cell.

    I hope it clears the confusion.

    Regards,

    Jitender

    ClearSelection_Modified.zip

Need extra support?

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

Learn More

Forum Channels