Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
155
Ultragrid - Cell Activation without Row Activation
posted

I'm trying to figure out the best way to achieve the following functionality for my ultragrid (v14.2).

-For a grid of "samples," the sample to display should be chosen only by the user clicking the row selector or using the up or down arrows when the row selector is in focus. Highlight this row in the grid. Currently this is somewhat bound to the active row. I use the ElementFromPoint method in the MouseDown event handler to determine whether the user clicked the RowSelectorUIElement object, and the BeforePerformAction event handler with the UltraGridAction property to determine if the up/down keys were used.

-All columns are readonly except the "Selected" column, which is a checkbox. This property is used to apply actions to multiple rows at once.

-Clicking a cell in the "Selected" column toggles the checkbox. Clicking any other cell should simply highlight the text.

-When the user clicks a cell in the grid, it should not change the active row. 

Here's is some of the relevant grid initialization code I have. 

gridSamples.DisplayLayout.Override.CellClickAction = CellClickAction.EditAndSelectText;
gridSamples.DisplayLayoutOverride.RowSelectors = DefaultableBoolean.True;
gridSamples.DisplayLayout.Override.RowSelectorHeaderStyle = RowSelectorHeaderStyle.ColumnChooserButton;
gridSamples.DisplayLayout.Override.SelectTypeCell = SelectType.Extended;
gridSamples.DisplayLayout.Override.SelectTypeRow = SelectType.Single;

foreach (UltraGridColumn c in e.Layout.Bands[0].Columns)
{
    //Only allow the checkbox column to be editable
    if (c.Key.Equals("Selected"))
    {
        c.CellActivation = Activation.AllowEdit;
    }
    else
        c.CellActivation = Activation.ActivateOnly;
}

The basic issue I have is this: I need a clear way in the grid to indicate which row is the currently displayed one (right now I do this through the blue highlighting of the ActiveRow). But as it stands now, clicking any other cell changes both the ActiveCell and the ActiveRow properties of the grid, so the ActiveRow is not synced up with what is displayed. Any help would be much appreciated!

Parents
No Data
Reply
  • 21795
    Offline posted

    Hello Daniel,

    From the code snippet, you provided, it seems that you are allowing user to click and activate any cell in the grid. Note that, after a cell activates the row cell is part of also activates. This action by default does not paint the row in blue. However, after this action the row may or may not become selected row, by default painted in blue. In your case, you set CellClickAction to EditAndSelectText. Therefore, the row will not be selected and will not be painted in blue by default.

    If I understand correctly, your issue you need to show to the user, which the active row is. To do so you can set ActiveRowAppearance. In addition, you may disable selected row appearance. You can use code like this:

    //  Highlight the active row
    e.Layout.Override.ActiveRowAppearance.BackColor = SystemColors.Highlight;
    e.Layout.Override.ActiveRowAppearance.ForeColor = SystemColors.HighlightText;
     
    //  Disable selected row appearance
    e.Layout.Override.SelectedAppearancesEnabled = DefaultableBoolean.False;

    Only for your information – active row is the row that has the input focus and there can be only one active row. Selected row is a row that has been selected by code or by a mouse click. A single mouse click, by default, activates and selects the row that was clicked. Another click with CTRL or SHIFT key extends the selection by default. However, even if you select all the rows only one of them is the active row.

Children
No Data