I'm new to Ultragrid. I'd like to string together a default value in a cell on an Ultragrid based on another value on INSERT. It works if I use the property on the designer but
I can't add the additional value. Something like:
UltraGridList.DisplayLayout.Bands[0].Columns["YES_NO"].DefaultCellValue = "The value for Joe is: " + choice;
I tried using something like this, but I don't know that the row will be zero.
UltraGridList.Rows[0].Cells["YES_NO"].Value = "The value for Joe is: " + choice;
Hi Tony,
DefaultCellValue applies to the entire column - which means it applies to every row. There's no way to apply a DefaultCellValue to a single cell - at least not with a property.
If I understand correctly what you are trying to do, then I think you need to use an event for this. Maybe AfterRowInsert. In this event, you could examine the row, look at it's index, and based on that, you could set the value of the "YES_NO" cell to whatever value you want.
Hi,
Thanks for your reply. This is new to me, so there may be a better/another way.
I was able to use the AfterCellUpdate event, but had set set a "search mode" flag so when searching it would read the value from the database and not from the cell values, otherwise I was getting a null value reference since FIELD1 and FIELD2 were not set yet.
So basically if FIELD1 or FIELD2 changes re-concatenate it in FIELD3:
private void UltraGridList_AfterCellUpdate(object sender, CellEventArgs e){ if ((e.Cell.Column.Key.ToUpper().Equals("FIELD1") || e.Cell.Column.Key.ToUpper().Equals("FIELD2")) & !searchmode) UltraGridList.ActiveRow.Cells["FIELD3"].Value = "CUSTOM CHG FOR " + UltraGridList.ActiveRow.Cells["FIELD1"].Value + " - " + UltraGridList.ActiveRow.Cells["FIELD2"].Value;}
Maybe I was confused by your original question, because this doesn't appear to be anything like what you asked. This code will be fired for any row, not just a new row. And it will only be hit when the user changes a value in the row. Your original post was talking about adding new rows - that's what DefaultCellValue does.
If you just want to calculate the value of a column based on other columns in the same row, then you should be using the InitializeRow event. This event fires when the row is initially created and also whenever a value in the row changes.
Hi
(This is working now, but I wanted to clarify) I have two other questions about group by and populating ultra dropdown which I'll post separately.
On Insert of a new row I want to string together a value in a field based on two other fields field 3 = field1 + field2.When populating the grid it should read from the database saved value.
When updating the value in field3 needs to change if the value in field1 or field2 is updated, (this is working on insert and change of field1 or field2), so I did something like:
private void UltraGridList_AfterCellUpdate(object sender, CellEventArgs e) {
if ((e.Cell.Column.Key.ToUpper().Equals("FIELD1") || e.Cell.Column.Key.ToUpper().Equals("FIELD2"))
UltraGridList.ActiveRow.Cells["FIELD3"].Value = "STUFF FOR " + UltraGridList.ActiveRow.Cells["FIELD1"].Value + " - " + UltraGridList.ActiveRow.Cells["FIELD2"].Value;
AfterCellUpdate fires any time the user updates any cell in the grid. Not just newly-inserted rows. So again, you seem to be describing one thing and doing something else.
If you ONLY want this to happen for new rows, then you should use AfterRowInsert (which happens when the new row is created) or maybe BeforeRowUpdate (which fires before the row is committed to the data source).