Powershell and Winforms controls - winforms

If $form.Controls returns a list of all the controls on the form, what is the syntax to return a specific control? I want to get a list of all the textboxes on my form, not every control that's on the form. Thanks!

You could filter the items in the Controls control collection with Where-Object:
$TextBoxes = $form.Controls |Where-Object {$_ -is [System.Windows.Forms.TextBox]}

Related

I want to create a ComboBox which allows the selection of multiple items.

How can I create a ComboBox which allows the selection multiple items and adds selections separated with commas in WPF?
I will answer as briefly as you asked your question... you could define your own ControlTemplate for your ComboBox with a ListBox in the Popup for the items.

Silverlight ListBox Items beeing displayed in a different order thant the Items collection

I have a ListBox in a Silverlight Application. I'm trying to make an editable listbox, so I use an ItemTemplate to have the controls i need in each item, like a textBox and buttons, and its working fine.
I'd like to have a line at the end of the Listbox with a button to add new items. Since this item won't be related to any of my domain classes, I'm using a plain object as a 'Filler', and then I have code that identify this item to show the button correctly.
myListBox.Items.add(new object());
The problem is that I want this "new Record" item to be kept always at the end of listbox, so when I need to insert a new domain record, i use this code:
myListBox.Items.Insert(myListBox.Items.Count - 1, domainItem);
When I debug the myListBox.Items collections, it is in the right order, with the "add new" button at the end, but the listbox is displaying this button at the beggining. Why are my items beeing displayed in a different order than the Items collection?
Unless there is a specific reason, instead of trying to put the button into the listbox collection itself you would be best to create a new control with the button outside and below the listbox. You can always style the button to look as though it's within the listbox if required.
Is there a reason why you are not using a datagrid because it would remove all your ordering problems and it would allow you to edit the entries.
The datagrid is bound to an ObservableCollection which automatically connects your editable fields to the GUI.
Cheers,

Data that updates other user controls in WPF

I currently have two user controls that both utilize a list of objects. These lists of objects are coffee types. These 2 user controls show the coffee types in different ways.
What I want to do is, when a coffee type is selected in one user control, it will update or highlight the same coffee type selected in the other user control.
I tried making an ObservableCollection that both user controls would look at, but it did not work out.
Any other ideas?
Thanks!
The droids you are looking for: Selector.IsSynchronizedWithCurrentItem
You can set the IsSynchronizedWithCurrentItem property to true to ensure that the item selected always corresponds to the CurrentItem property in the ItemCollection. For example, suppose that there are two ListBox controls with their ItemsSource property set to the same source. Set IsSynchronizedWithCurrentItem to true on both list boxes to ensure that the selected item in each ListBox is the same.

How to 'get at' the WPF combobox PART_EditableTextbox because combobox not getting highlighted?

My WPF combobox is populated with a different set of strings each click of a button. There are other controls on the window as well. The combobox is the 'first' (top) in the window, but the text doesn't get highlighted. When the user tabs through the controls, the text DOES get highlighted, but when it's the first on the window, it doesn't.
Maybe i need to force a highlight on the individual textbox control 'within' the combobox itself, but how would i do this? I couldnt seem to find the internal 'structure' of this control anywhere. Could anyone help here?
Jack
to get the TextBox of Combobox you can use
TextBox TxtBox = (TextBox)myCombo.Template.FindName("PART_EditableTextBox", myCombo);
I'm not sure it's the best solution, but you can use FrameworkElement.FindName to access the child control -- it's guaranteed to be present in a combobox, because it's a key constituent part of the control.
That stated, is it not better to try and call .Focus() on the control? That is likely why when you tab, the highlight is provided.
Another option is to derive from ComboBox, and expose the child text box as a property allowing you to set it's selection, or add a method directly to the combobox to set it for you.

Multi selection list box in WinForms

I am looking for way to implement multi selection enabled list box in windows forms C#.
Any suggestions?
Thanks.
Just add a ListBox control and set the Property: SelectionMode = SelectionMode.MultiExtended
Then you can get the selected items in: ListBox1.SelectedItems

Resources