Databound Listbox in Wizard loses selections on page change - c#

I downloaded the source code from this tutorial after a failed attempt to make my own Wizard. The control works great and is integrating nicely into my program. I have one minor problem, though. I have a page that has both a databound ListBox and a databound TreeView. When changing to the next or previous page, the TreeView maintains its selections but the ListBox does not. Instead, it appears to update itself (judging by the flash). How can I prevent this from happening and maintain the user's selections?
Thanks,
Joe

Ugh! Serves me right for re-using code that I haven't looked at in a couple of months. Turns out the TreeView is not data bound but populated from a Value Object. I modified the ListBox to use its own VO and now it works perfectly. Kind of a complicated way of doing things but whatever works, right?

Related

Creating a custom listview in WPF C#

I am currently looking for what is best practise when creating a dynamic listview, this will contain a list of clients and once the user clicks this will expand a detailed expander style. I have in the past used user controls, adding a new one each time, however this caused performance issues.
Take a look at this page. This seems to be exactly what you want. Instead of a listview, it uses a datagrid.

Master/Details in windows form c#

I have the master details "pattern" in a windows form.
For example, I have a bill (master) with a list of items (details) the user will add.
However, the user will add the items manually.
In order to achieve this, I used the data repeater but it caused a lot of problems when the scroll appears.
I spent several hours trying to fix this issue (the selected value in the combobox in the repeater gets mixed as the user scrolls down).
Are there any other controls anyone ever used for the same purpose?
I don't thing the DataGridView will provide me with the same flexibility.
Also building a complete set of dynamic controls is a huge overload.
Suggestions?
Note: I m using .net framework 4.5

Visual objects that change size in c# displayed in a linear list

Please forgive any silly words I may say. I am coming from a Actionscript3 background.
I am using "Visual C# 2010 Express".
I have a simple Form, in a WindowsForm Project, which currently holds just a Listbox. (Which I presume I will have to change to something else).
And I made myself a different display object (User Control) that is currently a Checkbox a title. (More will be added once I get over the hurdle below)
But I can't even get as far as Displaying the UserControl as a list.
I can't seem to find anywhere on the listbox to say "User this displayobject as the visual for listbox". I see tutorials saying "ItemsPanelTemplate" but I get error saying there is no such property for a Listbox.
I even tried making the Form in Design view and it is not in the list down the side of the GUI when I dragged as Listbox on screen.
Now I know how I would do this in pure Actionscript, but I dont know how to do this in Pure C#. Tutorials are not helping, as all the Microsoft site seems to try to give me is XAML (XML). and I am looking for C# code. So I have thrown in the towel and pleading for outside help.
Thank you for any help you can give.
It sounds like you want a list of items, each with a CheckBox and some descriptive text. Try using the CheckedListBox control. MSDN link.
This question also answers the question of how to do custom image drawing for each item in a ListBox. It may be helpful.
Edit after clarification:
Try embedding the UserControl in a ListView, rather than a ListBox.
References on embedding controls in ListViews:
C# listview - embedding controls
Adding button into a Listview in WinForms
You could also use a list of Panels, with each Panel hosting a UserControl.
C# List of Panels
But the real answer, as seen in the question's comments, is that Winforms doesn't have a convenient way to do this. This is a task much better suited to WPF.
You may check out freeware component Better ListView Express from ComponentOwl. It supports simple Details view without columns, two and three-state checkboxes, images and more...
They also offers full version with even more nice features like hierarchical and multi-line items.

Switching controls based on Combo Box Value

I am looking into developing a GUI that will switch the controls based on the value of the selected combo box item.
I have tried adding a different canvas or grid to the gui designer in visual studio but it comes hard to manage as everything overlaps each other in the designer and is hard to know what's what.
Is there an easy way that I can do this, is there a particular control that makes this easy to achieve. I don't really want code the gui in c# and not use xaml.
What I was hoping to do is that all the controls are in there own panel and when the combo box value is changed one panel is removed or hidden and the other is shown.
How can something like this be achieved.
Thanks for any help you can provide
You could implement each different "mode" as a separate UserControl.
Then have a shell with the combobox, where the combobox OnChange will swap out what UserControl is plugged into the shell.
Any other totally common components such as OK/cancel buttons could be part of the shell.
A completely alternative implementation to consider is a tabbed approach, but that probably only flies if it makes sense for the user to act on several of them.
What will you do if the user selects A in the combo, makes changes in UserControlForA, and then selects B in the combo? Could be an annoying corner case, and if this is production code the sort of thing that you'll get future user requests to change how it works.
If you're sure of the design go for it. If not, I'd play around with a few apps and try to find a nice example of the same sort of thing, and consider how they approached it.
But techwise I think a UserControl is what you're describing.
(Edit: crud just saw the xaml/wpf in the question, not sure this is correct in that context, clueless there)
You can use DataTemplate for each different mode.See Different item template for each item in a WPF List for more information.

Strange behavior in ASP.net regarding WebControl vs UserControl ViewState

Ok, I've solved my problem but I don't know why one type of control works and another doesn't.
The scenario: I'm working on a custom wizard style page design that was originally done completely with UserControls in C# ASP.Net 4.0. The step that you are viewing is controlled on server side via control visibilty.
My problem: I dislike the UserControls and want to use WebControls as much as possible, though it's not worth my effort to redo the entire thing with WebControls, and new controls are needed to expand the functionality.
My original solution: I initially started creating WebControls as needed. This worked fine until I got 2 steps away from a given WebControl, where it lost it's ViewState. At least I believe that is what happened. It was a CheckBoxList and as soon as I was 2 steps away, the ListItems disappeared.
The final solution: Recreating the same control as a UserControl I always have access to the CheckBoxList Items.
This all seems fairly logical. If a control or one of it's parent's is not visible, it won't be included in the ViewState data. I guess the real question is, why does UserControl work?

Categories