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.
Related
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.
I'm creating a control, and adding a property (control's look depends on it). How can I set this property:
I can't set the property in form constructor immediatly after InitializeComponent() call. In this case user will see two frames of form initialization: the first — after InitializeComponent(), and the second — after property setting, that invoke control's redrawing. Bad.
Also, I can't mark my propperty with BrowsableAttribute, cause a type of the property, is my own class, that can't be configurated in «properties window». Аlso bad.
So, how could I inicialize the property between form1.SuspendLayout() and form1.ResumeLayout(false)?
Ideally, I would like to have possibility to write a code directly in a respective field of «properties window». For example I would write new MyClass(param1, param2), if type of the property is MyClass.
Don't force the controll to redraw on property change. It's not necessary when you initialize the control and when a user change the property it will be redrawn in the next paint event. If needed the user can call .Refresh() on your control after setting the property to force the redraw manually.
I have 2 grids. When user is doing edits in one grid, I want to disable the other grid from getting focus, or atleast other grid from changing its foccussed row.
Example:
Parent grid, children grid.
If user is making edit in children of particular parent. I want to prevent user from suddenly shifting focus to different parent row. how to do that ?
The only ways you can prevent a control receiving focus is to change it's Enabled or Visible properties.
Simply changing the parent's Enabled property to "false" (e.g. for the CellBeginEdit) and then back to "true" (e.g. in the CellEndEdit event) will prevent the user from selecting a new parent row.
There are a lot of ways to do this but thats how I would do it (just a concept so ignore if any property does not match):
Create a property called mode and then use enumeration to set it to Edit or None etc.
Suppose you have GridViewParent and GridViewChild. In the FocusedRow event of child grid, at the start of all code, set the value of mode to Edit and at the end of all code in the event set it to None.
Then in the FocusedRow event of parent grid check whether the mode value is edit or not, if it is edit then use e.Cancel or something to get out of the focused event of the parent.
Now if you let me know exactly which grid are you using I might send you the code.
If we hide a control with Control.Hide(); in C# (win-forms) does the Control lose its Functionality, in that way that Control's Stop's its Execution like if we Have an MP3 Player Control and if we Hide it does it Stop Sounding, or if we Populate Data in a DataGridView than if we Play with it's Visibility does GridView clear it's Data .
If the Control does lose ,what can i do to prevent it and if anyone knows why?
PS: Where is e Difference between Control.Visible = false; and Control.Hide();
The control will not lose its functionality. It is still an object in memory and if you call any method on it, it will execute. Hiding it simply means it does not display on a form anymore.
In your example, hiding a control will not automatically stop the sound, unless that is built into the hide function.
As for you PS - from MSDN, Control.Hide Method:
Hiding the control is equivalent to setting the Visible property to false. After the Hide method is called, the Visible property returns a value of false until the Show method is called.
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.