Add buttons into a grid example?

Does anyone have an example of adding buttons into a grid?

I’m finding some examples with a google search on infragistics, but I don’t quite understand all of what I’m reading. I’ll start experimenting, but if anyone has an example that will get me farther faster, that would be appreciated.

If I get it figured out I’ll post what I did to make it work.

Thanks in advance.

Here’s a quick snippet of me adding a radio button to a grid

private void grdSigners_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs args)
	{
		// ** Place Event Handling Code Here **
		
		//add mutually exclusive boolean to the grid to select primary signer 
		args.Layout.Override.RowSelectors = Infragistics.Win.DefaultableBoolean.False;
	    args.Layout.Override.MinRowHeight = 20;
	    args.Layout.Override.DefaultRowHeight = 20;
	    
	    args.Layout.Bands[0].Columns.Add("Primary");
	    args.Layout.Bands[0].Columns["Primary"].DataType = typeof(bool);
	    args.Layout.Bands[0].Columns["Primary"].Header.VisiblePosition = 0;
	    //args.Layout.Bands[0].Columns["Primary"].EditorComponent = this.grdSigners;
	    
	    args.Layout.Bands[0].Columns["Primary"].Width = 16;
	    args.Layout.Bands[0].Columns["Primary"].MinWidth = 16;
	    args.Layout.Bands[0].Columns["Primary"].MaxWidth = 16;

		grdSigners.DisplayLayout.PerformAutoResizeColumns(false, Infragistics.Win.UltraWinGrid.PerformAutoSizeType.VisibleRows);
		
	}

Might get you thinking in the right direction

1 Like

Yeah, I’ve done radio buttons before. The difference between this and radio buttons is to get the button wired up to do an action.

I was able to add this code and it gets me some buttons

		workGrid.DisplayLayout.Bands[0].Columns.Add("CompleteQty","Action");
		workGrid.DisplayLayout.Bands[0].Columns["CompleteQty"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button;
		workGrid.DisplayLayout.Bands[0].Columns["CompleteQty"].ButtonDisplayStyle = Infragistics.Win.UltraWinGrid.ButtonDisplayStyle.Always;

Now I just have to figure out how to get the event wired up. Looks like I need to use ClickCellButton event according to this page.

https://www.infragistics.com/community/forums/f/ultimate-ui-for-windows-forms/53470/how-to-add-buttons-in-the-datagrid-rows

I just have to figure out how to get that working since it doesn’t exist in the wizards.

as for adding the event handlers?
You could just hand type them into the initialize and destroy methods, just copy what you see for a wizard added section but mod it to fir your new button
looks like there is a built in wizard for the handler
image

and once you have an event handler built in you just do your code action off of that method

    private void yourGrid_ClickCellButton(object sender, CellEventArgs e)
    {
        if (e.Cell.Column.Key == "YourButton")
        {
            //do someting
        }
    }

thanks. Looks like I have to make a grid to get to that. It’s annoying that the wizard won’t connected to existing controls.

Is there a way to get a list of available arguments to use on an event handler? I’ve got it working to where I can click the button and get the message to pop up, but I need to get information from the row being clicked on. I’m trying to find some info in the object explorer but am having a tough time.

	private void workGrid_ClickCellButton(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs args)
	{
		// ** Place Event Handling Code Here **
		MessageBox.Show("Cell Clicked");
	}

that shows me one, which is the text in the cell. Is that the only thing I can get with it?

private void yourGrid_ClickCellButton(object sender, CellEventArgs e)
{
    if (e.Cell.Column.Key == "YourButton")
    {
        //do someting
    }
}

well it looks like you’ll be able to access properties of the cell (in this case “e”) like in this example

So I couldn’t figure out how to get anything else from the properties other than the key or the cell text (which there is none in this case) so I just ended up putting a foreach loop in there. It’s probably not the best way to do it, but that’s all I could figure out for now. If anyone has any better suggestions, let me know.

	private void workGrid_ClickCellButton(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs args)
	{
		// ** Place Event Handling Code Here **
		foreach (var row in workGrid.Rows)
			{
			if (row.Activated)
				MessageBox.Show(row.Cells["Calculated_TotalQtyLeft"].Value.ToString());
			}
	}

txtPartNo.Text = args.CurrentView.dataView[args.CurrentRow][“JobHead_PartNum”].ToString();

I use this on a deployed dashboard customisation. This happens to be on an AfterRowChange method - so basically I’m always setting my textbox equal to the value from the current row. You can hack this around a bit for your purposes.