Hi J,
Doesn't PerformAction return a boolean which indicates if the action was successful? If so, you could just skip the rest of the code if the PerformAction fails.
If I am wrong and there is no such return value, then you could check to see if the grid is still in edit mode after you call PerformAction. If so, you know the PerformAction failed and again, you can skip the rest of the code.
jammerms said:if ((grid.CurrentState & UltraGridState.InEdit) == UltraGridState.InEdit) ... Is that the best code to test this condition?
That works, but this is easier:
this.ultraGrid1.ActiveCell.IsInEditMode \
jammerms said:Now I have another question: when a cell button is clicked on the row, I put the same condition in to test if the cell value is no good and then return. BUT, if it was the Delete button that was clicked (and only the Delete button), I still want to do delete the row. However, I get the validation message before I get to the ClickCellButton code where I can check if the grid's in the edit state and then return if it is. (If it's the delete button, I can still delete the row, but the user would have gotten the message box about the bad value, which I don't want to do.) Any ideas here?
If you want to delete the row, then you probably don't care about any changes in the row, so you can call CancelUpdate on the row first.
Mike,
Thanks for the tip on checking the active cell state. Regarding your second suggestion, to call CancelUpdate on the row first, when would I do that? I handle the button click code in ClickCellButton, where the validation message has already fired to the user. I can still delete the row, but the user still would have gotten the grid validation message (which is what I want to avoid). I'm sure this is an easy one, I just haven't spotted where to do it.
Thanks again,
Jamal
Hi Jamal,
Are you saying that the message comes up as soon as you click on the cell button? I would not expect that to be the case. I would have thought that the message comes up when you try to commit the changes to the row, which means you would call CancelUpdate first, before you call any other code in the CellButtonClick event of the grid.
If you are showing a MessageBox or some other dialog, then this might be causing the grid to lose focus and this try to commit the row. This is determined by the UpdateMode property. So maybe you need to temporarilty change the UpdateMode so that the grid does not try to update on a LostFocus.
How you are providing the button? Are you using the Style property of the column? Are you using Button or EditButton Style? Is the button in the same cell that is generating the error or in a different column?
I tried this out in a number of different ways, but I cannot get the button click to cause the grid to display an error. The only time this happens is when I try to leave the row.
jammerms said:Regarding disabling cells, setting CellActivation to Disabled greys out the columns. I don't want them greyed out, just not editable. So I set CellClickAction to RowSelect, and that seems to work.
You could also use a setting of NoEdit or ActivateOnly, which would prevent editing and not change the cell color. Or, you could use Disabled and set the DisabledForeColor on the cell's appearance.
Thanks again for your help. I have been working support issues, and am only now able to try this.
I've had the column from the datasource set AllowDBNull = false the whole time. When I took out the line set the ultragrid's column Nullable to Disallow, I get no validation from the datasource as the value of the empty cell is the empty string, not null or dbnull.
So I'm not able to skirt the issue that way. Looks like I'll have to manually validate the cell's value. Let me know if there's an easier way to do this.
Regarding disabling cells, setting CellActivation to Disabled greys out the columns. I don't want them greyed out, just not editable. So I set CellClickAction to RowSelect, and that seems to work.
J
Okay, I was able to reproduce the issue.
At a glance, it looks to me like the issue here is the Nullable property on the column. Since you are using the grid's column's Nullable property, the grid tries to validate the cell immediately when you try to leave it. The UpdateMode doesn't enter into it at all, because the grid is not committing the changes to the underlying data source at this point, it's just doing it's own built-in validation.
If, instead of using Nullable, your data source itself were set up to not allow nulls, then this validation would not occurr until you tried to update the row. So you might be able to work around this issue that way.
Oh... regarding disabling cells, there is an easier way. This KB article should help:
HOWTO:How can I make a grid or a column, row, or cell in the UltraWinGrid disabled or read-only?
The Name column does not allow nulls (in ugClinicalGroups_InitializeLayout: col.Nullable = Infragistics.Win.UltraWinGrid.Nullable.Disallow;), and the Delete column is the one with the button.
Here is some code:
In Initialize (_dtClinicalGroups is a DataTable)...
_dtClinicalGroups = _daoClinicalGroups.GetAllClinicalGroups(); ugClinicalGroups.DataSource = _dtClinicalGroups;ugClinicalGroups.UpdateMode = UpdateMode.OnUpdate;ugClinicalGroups.ActiveRow = null;ugClinicalGroups.Selected.Rows.Clear();
ColumnsCollection cols = e.Layout.Bands[0].Columns;
cols.Insert(cols.Count, "ASSIGN_USERS");
{
col.Header.Caption = "Delete";
col.Width = 50;
break;
Also, I subscribe to BeforeCellActivate to make sure only certain cells are editable (I set e.Cancel = true if it's a non-editable cell). Is this the best way to insure that only certain cells are editable?
Let me know if I can provide any additional information.
Thanks,