Enable scroll bar from disabled listview in C# - c#

I'm getting confusion. I'm set :
this.listView1.Enabled = false;
when i make do that listview's scroll bars are disabled, too. I want to see all listviewitems in listview with scroll bars when listview disabled. Please give me some advices. Thanks.

After a lot of comments, I'm assuming your listview, because of is updated often from many different threads, is flickering.
If so, one possible solution is to enable DoubleBuffering; this property anyway is protected so accessible only from descendant classes.
So you could:
Add a new class to your project and paste the code shown below
Compile
Drop new control from the top of the toolbox onto your form, replacing the old one
This could solve your problem.
using System;
using System.Windows.Forms;
class BufferedListView : ListView
{
public BufferedListView()
{
this.DoubleBuffered = true;
}
}
The idea is taken from this post on SO.

you can't scroll a disabled control, since scrollbars are part of the control itself (and it's disabled, so...).
if you want to scroll but not allow user to select anything, you could do this
this.listBox1.SelectionMode = SelectionMode.None;
if you want to revert it, you can set it to SelectionMode.One for single, or one of the other options for multiple selection allowance.
another (imho overcomplicated) option is making a user drawn ListBox.

You can't scroll a disabled control - but if you really need such a functionality, develop a user control.
Developing Custom Controls in C#
Hiding the scroll bar in CheckListbox
Writing your custom control step by step.

Maybe if you put your listview inside a Panel you can enable scrolling by setting up ScrollBars="Auto" on the Panel control

Related

In a property grid is there a way to unselect all grid elements programatically?

I am working on a project in which I am using a property grid to display the properties of the selected control.
The Property Grid is fixed to the left edge of the container and in the rest of the space I have the form I am designing.
On clicking a control on the form, the specific control’s property is getting selected.
In the above figure, I have selected the textbox and the textbox’s properties get shown on the propertygrid.
Here if you observe, by default, the Name property is highlighted as well.
Is there some way to unselect this property programmatically?
I have tried some suggestions online but none have helped. I am not able to find find a way to remove all selections from the PropertyGrid, but its behaviour seem to be different form a DataGrid...
Here is why I need this...
On selecting a control, if a property in the property grid is selected, then the property is getting modified.
For example, If i cut the control using Ctrl + X, the selected value in property grid is getting cut which in some cases is forcing user to set the property before modifying anything on the form.
I have tried selecting multiple controls, but in that case alse the selected property seems to be persistent
Since PropertyGrid uses DefaultProperty to select a property in its grid, as an option you can set DefaultProperty attribute at run-time for your object to a non-browsable property, for example:
this.propertyGrid1.SelectedObject = null;
TypeDescriptor.AddAttributes(someControl,
new Attribute[] { new DefaultPropertyAttribute("Site") });
this.propertyGrid1.SelectedObject = someControl;
Well, what you are trying are hacks. It is never a good idea to do such hacks particularly if you are not the only person that use the software.
In your case, the focus should be on the designer while you interact with it. So if the user press Ctrl+X, the designer should respond to the keyboard and it should not have any effect on the property grid (as only one control can have the focus at the same time).
Thus it is up to you to make sure that your designer is focusable, that it has the focus when initially displayed, that it get the focus when you press the TAB key. Pressing the TAB key again should put the focus on the property grid so that user can interact with the grid without using the keyboard.
If you have more than these 2 controls, then obviously TAB should also stop at any appropriate controls. Also, it can be a good idea to have some direct shortcuts like F4 to (show and) activate the properties pane.
If you are not able to make it works, then the best compromise would be to use another windows for the properties grid. By using a distinct Tool windows for the properties, it should not respond to the keyboard when the main windows has the focus.
Here are some links that might help you:
Panel not getting focus
Control.Focus Method() — See Remarks section.
In any case, you should not prevent Ctrl+X to works as expected when the property grid has the focus and a property is selected. Users don't like software that do not follows UI conventions.
As a software developer, you should as much as possible ensure that your application follows standard behaviors. I recommend you that you take one or 2 extra days developing your software properly instead of doing hacks.
Often, compromise to gain a few days will never be fix and will be a pain for many years. Better to do it right from the start. Unselecting an item in the property grid is not an acceptable workaround. Your manager should not allows you to do that.

TabControl with Alignment=Bottom and Appearance=Buttons

Does anyone know if there's a way to fix this issue in .NET/WinForms with the Visual Studio designer?
Basically, if you take a blank form and add a TabControl and then set the Alignment property to Bottom and Appearance property to Buttons (or FlatButtons), the TabControl doesn't have a panel to work with. I can't add any controls to the TabPage at all. Is there a work-around for this? I have a nested TabControl that I want to use bottom/button tab appearance and I can't get this to work at all. I suppose I could use standard buttons with panels that I toggle the visibility on, but that's less than ideal.
Bonus question:
Why when I set the Alignment to Right or Left (Appearance = Buttons) is there such a huge gap between the tabs and the actual panel in the Tab Page?
Thank you!
EDIT: Using .NET 4.0 w/ VS2012
Appearance property = Button is the issue. Modify it to Normal.

Tabbing in a loop through a winform

I have an application where I have several forms. Its a C# windows-form based application build in .NET 4.O. I have several forms where the user enters the data. There are grids where data is displayed and whole lots of controls on the form. Believe me! its a mess of so many controls. I have to setup the TabIndex for each control. I have literally disabled the TabStop property of certain controls I don't want to be tabed into it. However, still once I go through the order I want, I TAB it, and it works but once it reaches the last box then it takes 3-4 times more tabbing to get to the first field. I tried disabling the TabStop property for the controls I don't want. But I think there might be certain controls that I don't see but they might be included in the Tab property.
My question is that is there any way that I can set the TabStop property of all the controls on the winform to false and then set it to true for the controls I want to include only.
I also open to if there is any other way I can implement this?
If further explanation is needed, let me know!
I have attached a picture thats the order I want and then loop back but somehow its not working. Just in addition there is also two panels in the form and I have disabled their TabStop property to False.
Go to View menu and click Tab Order. This will activate the tab-order selection mode on the form. TabIndex value will be displayed as a number on each control.
Click on controls in order you need them to be tabbed. This will set appropriate values for TabIndex of controls.
After you finished, go to View menu and turn-off Tab Order.
Select controls you don't want to be tabbed and set TabStop = false.
One simple explanation is that you lost a control underneath another one that overlaps it. Or it is located beyond the edges of the Form. A good tool to find it back is View + Other Windows + Document Outline.
If that doesn't help then diagnose it by adding a Label and a Timer. Write the Tick event handler like this:
private void timer1_Tick(object sender, EventArgs e) {
if (this.ActiveControl != null) label1.Text = this.ActiveControl.Name;
}
You should try the following code:
foreach (Control ctrl in this.Controls)
ctrl.TabStop = false;
Also you can try to check the last tabindex. Then go to your form.designers.cs and find all controls with a greater tabindex and then remove them : add
ctrlTabStop = false;
I did not test any of this, so be careful : backup your *.designer.cs before.

How do I create a Tab Control with no Tab Header in Windows form?

I have created a Windows form using a Tab Control, but it has a header with it. I want to hide it. I am not able to do it using any properties of the Tab Control. Is there any property defined for hiding the tab header for the Tab Control without going through the code?
Use following code to hide the tabs or set these properties in design.
tabControl.Appearance = TabAppearance.FlatButtons;
tabControl.ItemSize = new Size(0, 1);
tabControl.SizeMode = TabSizeMode.Fixed;
You want the tab panels without the feature allowing a user to switch between them, so I suppose you want to create few separate sets of controls to be shown to the user one at a time. You can achieve this in several ways (you can choose one of them if you find it appropriate in your case):
Use several Panel controls instead of several tabs in the TabControl, however, it would be hard to work in the designer, because all the controls would be visible
Use different Forms instead of tabs to keep the layout parts separated. It can be ok, but you may not want to use multiple Forms, so it depends on a specific case.
and finally, the suggested solution:
Encapsulate each set of controls in a UserControl. This allows you to keep each layout separately, so you can easily design each of them without the other controls getting in the way ;). The the code handling each of the layouts would also be separated. Then just drag those controls in the Form and use set their visibilities appropriately to show the one you want.
If none of those suggestions work for you, let me know, so I can look for other possible solutions.
It's more easy as you think, you just drag the panel's window upper, so will be outside of the form.
Use DrawMode: OwnerDrawFixed will hide TabPage header text DrawMode : OwnerDrawFixed
Another way to achieve the same (or similar) is: You can remove tabs from TabControl.TabPages collection and then add the tab you want to show.
During the Form initialization I remove tabs (so into the designer I can easily manage them) and in some control event (as button click) I show the tab the user has to see.
Something like that:
// During form load:
ctrTab.TabPages.Clear();
// ......
// During button click or some other event:
if(rbSend.Checked)
ctrTab.TabPages.Add(pgSend);
else
ctrTab.TabPages.Add(pgReceive);
In this way the user can still see the header tab but just as title of controls group, he can't change/switch the current active tab.

Dynamic top down list of controls in WindowsForms and C#?

In our project, SharpWired, we're trying to create a download component similar to the download windows in Firefox or Safari. That is, one single top down list of downloads which are custom controls containing progress bars, buttons and what not.
The requirements are that there should be one single list, with one element on each row. Each element must be a custom control. The whole list should be dynamically re-sizable, so that when you make it longer / shorter the list adds a scroll bar when needed and when you make it thinner / wider the custom controls should resize to the width of the list.
We've tried using a FlowLayoutPanel but haven't gotten resizing to work the way we want to. Preferably we should only have to set anchoring of the custom controls to Left & Right. We've also thought about using a TableLayoutPanel but found adding rows dynamically to be a too big overhead so far.
This must be quite a common use case, and it seems a bit weird to me that the FlowLayoutPanel has no intuitive way of doing this. Has anyone done something similar or have tips or tricks to get us under way?
Cheers!
/Adam
If you don't want to use databinding (via the DataRepeater control, as mentioned above), you could use a regular Panel control and set its AutoScroll property to true (to enable scrollbars).
Then, you could manually add your custom controls, and set the Dock property of each one to Top.
.NET 3.5 SP1 introduced a DataRepeater Windows Forms control which sounds like it'd do what you want. Bind it to the list of "downloads" (or whatever your list represents) and customize each item panel to include the controls you need.

Categories

Resources