472,780 Members | 1,169 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

enable/disable buttons based on ListView selection

Hello,

I have a form that contains a listview on the left side and a column of
buttons on the right side. Only some of the buttons do I want enabled
all the time. The other buttons should be enabled only if something is
selected in the listview. That part specifically works but not very
well. It seems that I can only get the buttons to disable if I click off
the text of the items in the listview but still within about 10-20
pixels of the text. If I click way off to the right where there is still
whitespace then I guess it isn't considered a click on the listview and
no event is generated to disable the buttons.

In Java, clicking anywhere on a row in a list would register as an event
on the list item but it seems with C# the boundary for what is
considered the list item seems to be very small (and definitely doesn't
extend across the entire width of the listview). By the way, I only have
1 column in the listview and I'm using the list view type (as opposed to
details or large icons) if that matters. Any tips?

thanks
Jun 14 '07 #1
6 5344
Brandon,

To be honest, any comparisons to Java are rather moot, as there is are
no direct analogies between the model for visual controls there, and those
in .NET.

What are the events that you are connecting to in order to determine
when to enable/disable the buttons? Also, what mode are you viewing the
listview in?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Brandon McCombs" <no**@none.comwrote in message
news:46***********************@roadrunner.com...
Hello,

I have a form that contains a listview on the left side and a column of
buttons on the right side. Only some of the buttons do I want enabled all
the time. The other buttons should be enabled only if something is
selected in the listview. That part specifically works but not very well.
It seems that I can only get the buttons to disable if I click off the
text of the items in the listview but still within about 10-20 pixels of
the text. If I click way off to the right where there is still whitespace
then I guess it isn't considered a click on the listview and no event is
generated to disable the buttons.

In Java, clicking anywhere on a row in a list would register as an event
on the list item but it seems with C# the boundary for what is considered
the list item seems to be very small (and definitely doesn't extend across
the entire width of the listview). By the way, I only have 1 column in the
listview and I'm using the list view type (as opposed to details or large
icons) if that matters. Any tips?

thanks
Jun 14 '07 #2
Hi Brandon,

When a ListView's View property is set to List, LargeIcon, or SmallIcon,
the bound of an item in it limited to the item text. When you click on one
item in a ListView, you should see a dotted line around the item text, and
this is the bound of the item.

Only when you click inside the bound of an item, this item can be selected
and the corresponding events, such as SelectedIndexChanged,
ItemSelectionChanged events can be raised.

This behavior of ListView is by design. If you don't like this limited item
bound, you may use ListBox instead. You can handle the SelectedIndexChanged
event of the ListBox to get notified when different item is selected in the
ListBox.

Hope this helps.
If you have any concerns, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 14 '07 #3
Nicholas Paldino [.NET/C# MVP] wrote:
Brandon,

To be honest, any comparisons to Java are rather moot, as there is
are no direct analogies between the model for visual controls there, and
those in .NET.
The comparisons are only for your reference to help you visualize what
I'm talking about in case I don't give good descriptions.
>
What are the events that you are connecting to in order to determine
when to enable/disable the buttons? Also, what mode are you viewing the
listview in?

I'm connecting to the click event. I mentioned in the previous post I'm
using the list view of the listview control.
Jun 15 '07 #4
Linda Liu [MSFT] wrote:
Hi Brandon,

When a ListView's View property is set to List, LargeIcon, or SmallIcon,
the bound of an item in it limited to the item text. When you click on one
item in a ListView, you should see a dotted line around the item text, and
this is the bound of the item.
I like the List view because I didn't want the items' text to wrap like
it does using Large/SmallIcon view.
>
Only when you click inside the bound of an item, this item can be selected
and the corresponding events, such as SelectedIndexChanged,
ItemSelectionChanged events can be raised.
Well it doesn't make sense that even though I'm not clicking on the text
(but still within the ListView bounds) that a click event is not being
generated. Why is the item and not the listview itself generating the
event (or so it seems)? If I click in the listview (with no item
previously selected) but not on an item in the list nothing gets
selected but yet if I click in the same spot after something is selected
that item stays selected: it isn't consistent in my opinion. It is
consistent from the point of view of no event being generated to change
the selection state but not from the point of view not having anything
selected if I don't click on an item.

In fact, the proximity to which I have to be to the item to get it be
selected w/o actually clicking on the item itself is not the same
proximity that I need to be within when I click to de-select the item: I
have to click further away from an item to de-select it so that's
another inconsistency.

If the ListView is generating the events then I shouldn't have to always
click on an item in order for a click event to be generated. Not
clicking on the item would show SelectedItems.Count to be = 0 and
clicking on an item would show SelectedItems.Count to be = 1, simple.

I'll try the ListBox. Maybe it will be more sane.
>
This behavior of ListView is by design. If you don't like this limited item
bound, you may use ListBox instead. You can handle the SelectedIndexChanged
event of the ListBox to get notified when different item is selected in the
ListBox.

Hope this helps.
If you have any concerns, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 15 '07 #5
Hi Brandon,

Thank you for your reply.
>Why is the item and not the listview itself generating the event (or so it
seems)?

It's indeed the ListView that raises the events, such as
SelectedIndexChanged and ItemSelectionChanged.
>Well it doesn't make sense that even though I'm not clicking on the text
(but still within the ListView bounds) that a click event is not being
generated.

In fact, when we click within the ListView bound and no matter whether on
the text or not, system sends the WM_LBUTTONDOWN and WM_LBUTTONUP messages
to the ListView. ListView processes these Windows messages and then
determine whether to raise the Click event depending on the clicked spot.
If I click in the listview (with no item previously selected) but not on
an item in the list nothing gets selected but yet if I click in the same
spot after something is selected that item stays selected.

I don't reproduce this in my test. If no item is currently selected and I
click somewhere in the ListView(not on an item), nothing gets selected. If
an item is selected and I click the same spot within the ListView, the
previous item gets un-selected.
>I have to click further away from an item to de-select it so that's
another inconsistency.

In my test, only when the clicked spot is within the item bound, the item
will be selected. On the contrary, only when the clicked spot is out of the
item bound, this item will be un-selected.
>Not clicking on the item would show SelectedItems.Count to be = 0 and
clicking on an item would show SelectedItems.Count to be = 1, simple.

Yes, it's true in my test. If there's no item selected, the
ListView.SelectedItems.Count is 0 and if there's one item selected, the
ListView.SelectedItems.Count is 1.

Hope this helps.
If you have any concerns, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Jun 20 '07 #6
Hi Brandon,

How about the problem now?

If you have any concerns, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Jun 22 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES...
9
by: Susan Bricker | last post by:
Hi. I have two questions ... (1) I want to use a Listbox to enable the user to select 1 or many items from the list. However, I'm having trouble figuring out how to find out t which items have...
2
by: Dntc | last post by:
Hi All Is there anyway to enable/disable the toolbar buttons on the fly as like in MFC which helps centralizing this process?Let's i have a toolbar button ToolbarButtonSave which can be...
1
by: JC | last post by:
I am a newbe to C#, and I am required to enable and disable rows in a listview, depending on certain criteria. e.g. The listview contains - Apples Oranges Grapes I am required to have...
2
by: Steve_s | last post by:
Hi I have a number of control buttons and tabs on a main form which I would like to be disabled until a selection is made in a list box, after which the controls would be enabled. All of the...
1
by: scanreg | last post by:
My form needs to (1) direct to specified URLs based on a combination of form selections and (2) enable/disable form features based on selections within the form FORM Radio 1 - A - B - C ...
1
by: inadsad | last post by:
Good Day, I have 2 forms with bindingNavigator and have a simple routine to enable/disable navigator buttons. Each nav button is assigned to a tag value. The problem is that if I want to...
3
by: Pietro | last post by:
Hi all, First of all I'd like to thank you very very much ,as finally after many years of searching,I could find a code to disable/enable the shift key,but actually i cannot use the code as I'm...
3
by: =?Utf-8?B?UGxhdGVyaW90?= | last post by:
I have link buttons in a Gridview that, depending on the value in another column (Not the Key column) will need to be disabled. For example, (Column2 has link buttons) Column1 ...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.