-2

I tried this way, but the button does not appear even though the items are larger than 0.

enter image description here

How can I do this?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • Without more code it is difficult to see why not. It might be that you are expecting that snippet of code to fire, but it is not. Where is that called? – monstertjie_za Dec 12 '22 at 18:40
  • 1
    Welcome to Stack Overflow! Relevant code and error messages need to be included in your question *as text*, [not as pictures of text](https://meta.stackoverflow.com/q/285551/328193). Just linking to screen shots makes it more difficult for people to help you. To learn more about this community and how we can help you, please start with the [tour] and read [ask] and its linked resources. – David Dec 12 '22 at 18:41
  • 1
    Not my downvote, but posting an image of technical information like code, instead of formatted text, is the fastest way I've seen here other than spam for a question to be downvoted and then closed or ignored. – Joel Coehoorn Dec 12 '22 at 18:48

2 Answers2

4

It's not enough to set it to false if you don't want it to show. You also need to set it to true when you want to see it again. But you can write one line that does both:

btnRemoveToCart.Visible = (lbxCart.Items.Count > 0);

Now we also no longer need the if() check.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
1

Try add

else
{
    btnRemoveToCart.Visible = true;
}