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
1145
Selected Row Color via UltraOptionSet
posted

Version 9.2 - UltraOptionSet with two options: "Buy" and "Sell".  When "Buy" is checked, any selected rows need to be Color.Lime, Color.Pink for "sell".  I don't pick the colors  :)

The grid's selection strategy is overridden based on another forum post so that we only allow certain bands to be selected based on other control options.  Then use the mouseup event to see if a row selector element was clicked and toggle the selection of the row:

private void gridBuySell_MouseUp(object sender, MouseEventArgs e)
{
    UltraGrid grid = sender as UltraGrid;

    // Get the row that was clicked on, if any.
    UltraGridRow row = this.GetRowFromPoint(grid, new Point(e.X, e.Y));

    if (row != null)
    {
        if (row.Band.Index == _LevelOfDimension)
        {
            // Clear any cell or column selection.
            grid.Selected.Cells.Clear();
            grid.Selected.Columns.Clear();

            // Toggle the selection of the row.
            row.Selected = !row.Selected;
        }
    }
}

So, I need to probably try something here in this event(?), which I have:

if (row.Selected)
{
    switch (_BuySellInd)
    {
        case "Buy":
            row.Appearance.BackColor = Color.Lime;
            break;
        case "Sell":
            row.Appearance.BackColor = Color.Pink;
            break;
        default:
            row.Appearance.BackColor = Color.White;
            break;
    }
}
else
{
    row.Appearance.BackColor = Color.White;
}

I found other posts on the web where the solution was to use the "RowSelectionChange" event, but this event is not in version 9.2.  I did try the same code above in the grid_BeforeSelectChange with no luck, mainly because you don't know if the row was selected or de-selected.  Thanks!!!