Thijser Thijser - 2 months ago 14
C# Question

How to react to a onlick in an ultragrid

I have code that creates an UltraGrid with a column that has the

ColumnStyle.Button
as it's style.

private void Grid_InitializeLayout(object sender, InitializeLayoutEventArgs e){
Grid.ResetEmptySelectedAppearance();

var column = Grid.SetColumn("Draw Lines", "Draw Lines", 30);
column.Style = ColumnStyle.Button;

Grid.HideOtherColumns();
}


Now I would like too make it react to being clicked on. I have found this but it does not show me how to bind the variable, usually I can either double click in the visual studio editor (but in this case this only directs me too the
Grid_InitializeLayout
) or I can go the the item in question and add the function to an
OnClick
variable, but this one doesn't exist.

private void Grid_InitializeRow(object sender, InitializeRowEventArgs e)
var buttoncell= e.Row.Cells["Draw Lines"];
//something here?


this is what I want to call

private void OnDrawLine(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
{
Debug.Print("test test");
}


It's probably something trivial but I'm stuck.

Answer

The UltraGrid responds to clicks on a cell button as explained in the link posted using an event called ClickCellButton. You need to subscribe to this grid event in the usual ways. (Designer or code doesn't matter)

private void Grid_ClickCellButton(object sender, ClickCellEventArgs e)
{
    // Check if the click happens on the required column
    if (e.Cell.Column.Key == "Draw Lines")
    {
        ... your code ...
    }
}
Comments