Changing the selection of RadioButtons in a GroupBox within a DataRepeater will change the selection of other RadioButtons - vb.net

I have a DataRepeater in which I have a Label (LabelID) and a GroupBox which contains RadioButtons. I am binding the Labels to a column from a DataTable and what I wish to do is to give the user the chance to select one of the Radio Buttons within each cell of DataRepeater and then upon progress I wish to read the user's selection for each cell. The problem is that when the user starts selecting the radio buttons and scrolls down to select radio buttons for other cells within the DataRepeater, the previous selections change or even the ones that user has not selected yet get selected. I have no idea why this is happening.
Here is the code for what I have done:
LabelID.DataBindings.Clear()
LabelID.DataBindings.Add(New Binding("Text", SomeDataTable, "SomeID"))
myDataRepeater.DataSource = SomeDataTable
I added the GroupBox which contains the RadioButtons in the Visual Studio drag and drop framework.
I tried the following binding as something that I thought might solve the problem, but it did not.
GroupBoxSelection.DataBindings.Clear()
GroupBoxSelection.DataBindings.Add(New Binding("Tag", SomeDataTable, "SomeID"))
I know it has something to do with scrolling the DataRepeater up and down. Because I increased the size of the DataRepeater to get rid of the ScrollBar and this strange behavior won't happen anymore. I cannot keep the DataRepeater that big so I would like to find another solution.
Any help will be appreciated?

I don't know how the DataRepeater works exactly but I wouldn't be surprised if it reused controls to increase performance. If so then your controls may be retaining their values as they are moved. What you might try is creating a user control to contain the RadioButtons and expose a single property that you can then bind. If an instance gets reused then the binding should update correctly as it does for the other controls.

Related

Panel scroll reset interfering with DataGridView usage

I've created a datagridview with a datagridviewcombobox in the end column. The datagridview is on a panel with AutoScroll set to TRUE. The combobox column is the only editable column.
My problem is that after scrolling down, if i then click onto a row the panel scroll goes right back to the top so i have to scroll all the way back down again. Then only if i click in exactly the same row will i be able to make a selection change in the combobox otherwise the same jump back to the top occurs. This is extremely annoying and adds much time to usage as well as making it much harder to make the change where needed. I've tried to catch various datagridview events (RowEnter, CellLeave, RowValidated) and set the panel VerticalScroll.Value at that point but nothing seems to work and that jump back to the top always occurs. Everything else seems to work fine and i'm able to update data based on the combobox changes.
Any advise would be really great.
Thanks in advance.
Younis

maximize listview when form window is strteched at runtime

I am using vb.net, I have created a form and there are two listviews in that form which are getting filled by button event. Every thing is going smooth, but the problem is when my exeute my project and in the form, when I maximize the form window(by clicking maximize button provided in the top right corner) the size of listview remains same while form maximizes, this looks odd, what i need is to maximize the listview also with the increase in the form window size.
I searched in google a lot and i found one property 'dock' of listview which i can set left, full, right,bottom,top or none, but this doesn't serve my purpose.
Snapshot when I am using Anchor property
On Starting:
After Maximizing:
Please guide me in the right direction, what I need to do
when no propety is set then image on maximizing is:
Thank you
With Regards
Better than Dock property, you have to use "Anchor" property. All controls on the Form has Anchor Top,Left by default, but you can change it in the property window or directly by code. You can know more about anchor on this site: http://www.homeandlearn.co.uk/NET/nets13p1.html
Anchoring two Listviews on a form depends on the form design, but SplitContainer control will be really usefull if you want that both Listview changes the size on form resize.

What technique will I use if i want to change this panel when I click a button in VB

I just have it in my mind. And I can't explain it so here it goes.
A system that only uses 1 form?
It have a two panel, left and right.
The left is consist of buttons
Then the right is associated on the buttons and will change whether what button will be clicked.
Any ideas?
My preference is to do this via custom controls, rather than panels... but panels can work too.
There are a number of ways to do this:
Keep all of the controls layered on top of each other, and then set the Visible property to false for controls/panels you don't care about and to true for the Control/Panel that you do
Move the controls you don't care about out of the visible area
Remove/Add the Controls/Panels from Form's controls collection entirely
I think you can also get a TabControl to put the tabs along the left side, with some formatting that looks more like buttons, such that what you want will be handled without needing to write any code to switch layouts
Any of those can work. Whichever option you use, I have two recommendation for controlling layout and making the transitions smooth.
Call SuspendLayout() before making any changes, and then call ResumeLayout() when you're done. This will help avoid stuttering or a partially rendered form.
Look at the TableLayoutPanel Control. This control will allow you to arrange your top-level panels so that they can be resized with proportion. If you also then dock your individual panels, you can quickly build your program so that it resizes correctly.
You can have several panels, one on top of another. Change their visibility, depending on which one you need at a given moment.
Option #2 would be using a vertical tab control (or a tab strip - see another answer there).

two nearly identical usercontrols with different resize behavior

I have an application which has a tabcontrol that contains two tabpages. I have a custom made usercontrol docked to fill up each of those tabs. When I resize my main form to the minimum size allowed one tab resizes accordingly while the other seems to overflow the area and a couple ui items slip out of access/view.
One usercontrol was quite literally copied from the other and renamed and fields adjusted. The usercontrol size is the same between the two. Within the usercontrols there is a datagridview and a large panel full of textboxes and they have identical sizes and identical anchoring properties and even the same location coordinates.
I'm struggling to find a difference between the two but I really would like the resize behavior to match between the two usercontrols. I was wondering if anyone would have ideas of other things to check I did not mention here?
This should like very odd behavior.
There are a few things that I can think of to check:
1) Double-check that the user control is actually on the tab page itself and not on a different control, such as the tab or a common tab area (not sure of the tab control you are using; some controls have a common area that is available to all tabs).
2) Verify that the Dock property is indeed set to fill on the "bad" usercontrol.
3) Verify that you are not resizing or changing the Dock property on the bad usercontrol in code.
Found a minimum size on one of the usercontrols and that was the cause of my issue. Don't know how I didn't see it earlier.

FlowLayoutPanel not showing all contents?

Very weird situation going on with a FlowLayoutPanel...
I have been dynamically adding user controls to my panel. This user control has a height of 105. If I have my FlowLayoutPanelwidth to only show 1 "column" of controls, it will only display 296 of them. The rest of the controls are grayed out at the bottom of the flowlayoutpanel. If I widen the flp to allow 2 "columns" of controls, I can see 592 of them, with the remainder grayed out at the bottom. I have gone in and resized the user control to make it shorter in height, which works in some respects (i.e. it works when I have two columns, but not just 1), and can go forward with this work-around.
So, I guess my question is, why does the FlowLayoutPanel behave in this fashion? It seems (based on what I saw) that there is a limit to how much data the FLP will show at one time.
Your comment just reminded me that when you're adding many controls to any container it is a good idea to do this:
YourPanel.SuspendLayout();
// populate panel with controls
YourPanel.ResumeLayout(false);
This in effect stops the container (panel) from re-rendering itself every time you add a control until you're done adding controls. In the very least your panel creation will be smoother and faster. Not sure if this might fix your issue or avoid the need for a hack with PerformLayout.
If you look at your Form's designer file you will actually see this in action in the InitializeComponent function.