Like Tree3Likes

how to select on the valid listview items?

This is a discussion on how to select on the valid listview items? within the C++ Programming forums, part of the General Programming Boards category; Hi guys, Can you please help me with my listview items. I want to know that when a user select ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    40

    how to select on the valid listview items?

    Hi guys,

    Can you please help me with my listview items. I want to know that when a user select the items on the listview to tick and untick on the checkboxes while a user do not select on the other listview items, how do the program suppose to know which listview items that a user have selected after tick and untick on the checkboxes?

    Something like this:

    Code:
    for each (ListViewItem ^checkeditems in listView1::SelectedItems)
    {
    	if (checkeditems->Selected == true)
    	{
    	 if (checkeditems->Checked == true)
    	 {
    		checkeditems->Selected = false;
    	 }
    	 else if (checkeditems->Checked == false)
    	 {
    		MessageBox::Show(checkeditems->SubItems[1]->Text);
    	 }
    	}
    }
    I need to know how to do this because I want to send the information of substring text to my php server.

    If you know how i can do this, I would be very grateful.

    Thanks,
    Mark

  2. #2
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Code:
    (checkeditems->Selected == true)
    Whenever you write "== true", god kills a sweet innocent kitten. You monster!

    Seriously though, nobody has even the slightest chance of helping you unless you tell us what GUI framework this is.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by Neo1 View Post
    Whenever you write "== true", god kills a sweet innocent kitten. You monster!
    If checkeditems->Selected is declared as "bool" that seems perfectly reasonable IMO.

  4. #4
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by Subsonics View Post
    If checkeditems->Selected is declared as "bool" that seems perfectly reasonable IMO.
    No, "== true" is never reasonable.

    Code:
    (checkeditems->Selected == true)
    Is equivalent to:

    Code:
    (checkeditems->Selected)
    Writing "== true" is basically just another way of saying "i don't know how boolean-expressions work".
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    2,545
    Quote Originally Posted by Neo1 View Post
    another way of saying "i don't know how boolean-expressions work".
    if it's a nullable bool, then "== true" is a perfectly valid expression, because System::Nullable<bool> doesn't implicitly convert to bool, but it does have an overloaded equality operator.

  6. #6
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by Elkvis View Post
    if it's a nullable bool, then "== true" is a perfectly valid expression, because System::Nullable<bool> doesn't implicitly convert to bool, but it does have an overloaded equality operator.
    What's your point? The code in question is pseudo-code, we obviously aren't talking about nullables or tribools or whatever. My point still stands, using "== true" in a boolean expression is fundamentally wrong. You found an exception to this rule, have some cake.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by Neo1 View Post
    No, "== true" is never reasonable.

    Code:
    (checkeditems->Selected == true)
    Is equivalent to:

    Code:
    (checkeditems->Selected)
    Writing "== true" is basically just another way of saying "i don't know how boolean-expressions work".
    So what, it comes down to opinion. You don't think it's reasonable because there is an equivalent short hand available, it's nothing wrong with explicitly typing it out. The short hand buys you nothing.
    Elkvis likes this.

  8. #8
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    i prefer
    Code:
    (! checkeditems->Selected != true)
    just to make people wonder
    Kurt
    manasij7479 likes this.

  9. #9
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by Subsonics View Post
    So what, it comes down to opinion. You don't think it's reasonable because there is an equivalent short hand available, it's nothing wrong with explicitly typing it out. The short hand buys you nothing.
    Wrong, my version is not shorthand for anything. There is something wrong with writing out " == true", if your expression evaluates to true, you don't then have to compare it to true, that's not the right way, that's stupid.

    You're essentially asking your computer to compare true to true, or true to false.

    The short hand buys you nothing.
    How does "true == true" buy you anything?

    Do you also write:

    Code:
    if( x > 5 == true)
    And would you consider:
    Code:
    if(x > 5)
    ..to be short hand?
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  10. #10
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,509
    Quote Originally Posted by Neo1 View Post
    <snip>..to be short hand?
    Yes.
    Similarly, (expression !=NULL) is also often written, when applicable.
    It simply increases the clarity, but can generally be skipped.
    Subsonics likes this.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  11. #11
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by Neo1 View Post
    Wrong, my version is not shorthand for anything. There is something wrong with writing out " == true", if your expression evaluates to true, you don't then have to compare it to true, that's not the right way, that's stupid.

    You're essentially asking your computer to compare true to true, or true to false.
    It's stupid to be confrontational. What am I doing? You say it's fundamentally wrong, which would mean that it's contrary to the standard, will result in undefined behavior, compile or runtime error.

    Quote Originally Posted by Neo1 View Post
    How does "true == true" buy you anything?
    It doesn't but that is not what we are discussing here. "true == true" is known to be true, "x == true" can be true or false depending on the value of x.


    Quote Originally Posted by Neo1 View Post
    Do you also write:

    Code:
    if( x > 5 == true)
    And would you consider:
    Code:
    if(x > 5)
    ..to be short hand?
    This is not a matter of what I do or don't do. It's you trying to make this into an error, it's not. It's a valid expression.
    Last edited by Subsonics; 05-06-2012 at 11:08 AM.

  12. #12
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    It's stupid to be confrontational. What am I doing? You say it's fundamentally wrong, which would mean that it's contrary to the standard, will result in undefined behavior, compile or runtime error.
    This really has nothing to do with C or C++ or any standard, this transcends languages. This is a matter of a gross misunderstanding of boolean logic.

    It doesn't but that is not what we are discussing here. "true == true" is known to be true, "x == true" can be true or false depending on the value of x.
    checkeditems->Selected is evaluated first, to either true or false. This is all you need to do. The OP then does a further comparison with true, which is completely redundant. After checkeditems->Selected is evaluated, the expression essentially becomes "true == true" or "false == true".

    This is not a matter of what I do or don't do. It's you trying to make this into an error, it's not. It's a valid expression.
    There are many valid expressions in C and C++ that should be avoided. This code isn't wrong, and it will do what it was meant to, but it certainly won't make for very good code.

    It's no different than this:
    Code:
    if( x > 5 == true)
    So i will repeat the question that you so elegantly dodged, do you consider the above snippet of code to be good? If no, then you cannot logically find the code in the OP to be any better, if yes then you are beyond reasoning.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  13. #13
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by Neo1 View Post
    It's no different than this:
    Code:
    if( x > 5 == true)
    So i will repeat the question that you so elegantly dodged, do you consider the above snippet of code to be good? If no, then you cannot logically find the code in the OP to be any better, if yes then you are beyond reasoning.
    It's a constructed scenario, I would not write something like that, ever. If you compare a bool, you can explicitly write out "== true" or "== false" if you think that makes the code more readable. It's a matter of style..

    Should you use a or b? I don't care because it does not matter, it comes down to style. You clearly have a very strong opinion about it, to the point that you are trying to convince us that it's wrong

    That is my only issue here, because that is a fallacy.

  14. #14
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by Subsonics View Post
    It's a constructed scenario, I would not write something like that, ever. If you compare a bool, you can explicitly write out "== true" or "== false" if you think that makes the code more readable. It's a matter of style..

    Should you use a or b? I don't care because it does not matter, it comes down to style. You clearly have a very strong opinion about it, to the point that you are trying to convince us that it's wrong

    That is my only issue here, because that is a fallacy.
    Redundant code is wrong. I could throw in an i++; i--; in my code, and it would compile, and it would conform to the standard, and it would work. But it would be wrong. And i would get called out about it if i put up any such code on this board.
    There must be a dozen beginning programmers in here every week, that get told to fix their indentation because it's wrong.
    I could use goto's as a replacement for loops, and it would be wrong.
    I could use preprocessor macros extensively in lieu of proper C++ control stuctures, and it would be wrong.

    ...it does not matter, it comes down to style.

    Extremely poor style is wrong. Throwing in an extra comparison left and right for readabilities sake probably means your naming convention is off.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  15. #15
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    What is extremely poor, redundant etc. will vary depending on who you ask.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. keeping track of listview items
    By Bleech in forum Windows Programming
    Replies: 0
    Last Post: 08-31-2006, 10:11 PM
  2. questions regarding listview items
    By Bleech in forum Windows Programming
    Replies: 7
    Last Post: 08-26-2006, 03:26 PM
  3. Moving items in a ListView
    By Cactus_Hugger in forum Windows Programming
    Replies: 1
    Last Post: 01-18-2006, 09:40 PM
  4. ListView Items
    By Smoose777 in forum C# Programming
    Replies: 1
    Last Post: 06-21-2003, 01:10 PM
  5. Selected Items in a ListView
    By Lowas in forum Windows Programming
    Replies: 12
    Last Post: 09-01-2001, 08:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21