i would like to add a column of buttons in an ultraGrid
the rest of the ultraGrid is populated with ultraGrid.DataSource = SomeValuesFromSql()
i would like to have a "Button" in each row, excluding the 'add new' row
i've tried the following code, but "Button Text" only appeared in the 'add new' row
UltraGridColumn buttonColumn = _grid.DisplayLayout.Bands[0].Columns.Add("Button Column"); buttonColumn.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button; buttonColumn.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.CellSelect; buttonColumn.DefaultCellValue = "Button Text";
if i tried the following hack, but the 'pens' appeared in every row's header, stating that the row is being modified
foreach(UltraGridRow row in _grid.DisplayLayout.Rows) row.Cells["Button"].Value = "Button Text";
and if you could make a suggestion on how not to show the button text in the 'add new' row...
thank you
Instead of looping through the rows in the grid, you should use the InitializeRow event to populate the Value of the button cell. This is more efficient than looping. It's also better to use e.Row.SetCellValue rather than referening the Cells collection.
I think if you set the value of an unbound column in the InitializeRow event, you won't get the pencil indicating an edit state for the row. But if I am wrong, then you can clear the pencil by calling e.Row.Update to commit the chanes after you have set the cell value.
You should probably also check the e.ReInitialize flag so that you only set the Value of the cell once.