Set value in UltraGridCell not firing events - c#

I have an UltraGrid with checkboxes in one column. I have an event that is fired when one of the checkboxes is clicked (checked or unchecked).
However, I want to set the value of the checkbox through code at a later time. I figured out how to do this by finding the UltraGridCell and doing cell.value = true; or cell.value = false;, but this isn't firing the event, which I need. I also found cell.SetValue(true,something), but I am not sure what to pass into something. The docs are no help, and I can't find an example that does what I want. Any ideas?

Which event are you using to determine when the value of the cell changes? If you use UltraGrid.AfterCellUpdate, it will fire when the cell value is set programmatically, either with the Value property or the SetValue method. The "something" you're curious about in the 2 parameter overload is a boolean value which indicates whether the value change should go onto the undo stack. If you pass in True, the user can perform an undo on the grid and it will undo your programmatic change. If you just set the Value property, it does not get added to the undo stack.

Related

LookupEdit: how to verify whether user changed value or not inside EditValueChanging event?

I want to raise warning dialog when user manually changes value from a couple of drop-down list. In case of negative answer previous value must be restored, so i decided to use *EditValueChanging event. But there is also one main drop-down list that also changes the value of all desired controls (some sort of default values setup) which causes multiple dialog messages to appear for each control which is not desirable. How can i verify that valuee were changed by user, not by code, to raise dialog window?
Set a boolean value when you update the values from your "default values" setup and unset it when that routine completes, then predicate the EditValueChanging based on whether the boolean is set.

DataGridView cell causing validation on simple arrow keys

Why does DataGridView raise CellValidating event upon simple navigation through arrow keys? How can I prevent it? Here is the key information about DataGridView state when it calls CellValidating:
EditMode = EditOnKeyStrokeOrF2
IsCurrentCellInEditMode = False
e.FormattedValue = [Same as the current value of the cell]
As you can see, user has not triggered any editing operation. He's just moving across the cells by pressing right-arrow key. One would not expect validation to occur at this point, right?
Note: Examining call stack shows that KeyDownevent triggers a CommitEdit call, which in turn raises OnCellValidating.
Like it or not, this is the way things are desigend to work. See MSDN on CellValidating:
Occurs when a cell loses input focus, enabling content validation.
And to make it complete MSDN on CellValidated:
Occurs after the cell has finished validating.
The most direct and readable solution is probably to put a line like this at the start of the CellValidating event:
if (!dataGridView1.IsCurrentCellDirty) return;
One reason for the designed behaviour could be the case where a user input is actually needed to create a valid cell value. Not your case, but still a conceivable requirement.

Trigger the visibility of control based on count

This is just a generic question related to C# and WinForm..
Is there any way to automatically trigger visibility of a control based on the count..
For example, I have a Boolean count which could be true or false.. If the count is True I need to hide some control and if its false I need to show the control.
Is it possible that changing the value of Boolean control can trigger the visibility function automatically? So that there is no actual call of Show / Hide control.. When the count value changes it automatically triggers the function which checks for the count value and shows/hide the control?
At some point, there WILL be a call to Show() or Hide() or changing .Visible.
You can, in the designer, bind the control's .Visible property to the Count property (seriously reconsider the name for this) on your object. But that will really just pre-write the code for you.
When are you loading your object that has this boolean-count property? You could change the visiblilty of anything you like at that point.
Or, you could change the visiblity when your user edits the object you're presenting.

Checkbox (bool) can not be toggled in gridbox. C#

I have a DataGridView with a binding source to an interface that has a bool. When I click the checkbox that is created in the grid, nothing happens. The value is not set and the box does not get checked.
However, and this gets very case specific, if I set a binding source to a completely different control in the same view then the checkbox in the first control is possible to click. The downside to this is that every DataGridView when loaded has a large portion of it that is completely black.
sorry I have no point to make this as a comment.
anyway did you check that the column of the DataGridView is set as readOnly = false, or enable = true.
check it also in run time, make a break point before and after doing the binding and see how your grid is set up.
Also if you can give some code maybe will see some other issue that can make this happen.
good luck

Filter ComboBox by selected item of another ComboBox

I have a County ComboBox bound to an entity (EF). There is another ComboBox for Area's. These controls are in an edit form.
So the user has chosen these values. In this form the user can edit the chosen values. So when the window is loaded, the chosen values are selected as default. Each of these ComboBoxes has an SelectionChanged event.
The problem is that when the default value is selected (when the window is being loaded), the SelectionChanged event is triggered. Pretty obvious. But I want the event to be triggered only when the user really chooses another item (from County ComboBox) to filter the Area ComboBox.
How can I achieve this?
Use a public variable. Name it something obvious and intuitive like EnableEvents.
An example of using it, with a default value of True, would be:
Whenever you do NOT want your code to trigger the ComboBox's events, set EnableEvents=False and then inside the event handler, use something like a If Not EnableEvents Then Exit Sub.
Whether you default this variable to True, which will allow all events unless when you specifically change the flag to False, or default the variable to False which will disallow events unless you change it to True, is probably a matter of preference based on your specific needs. Whatever initial value you assign to it, just remember to reset it after each time you change it.

Categories

Resources