CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2007
    Posts
    448

    How to check the checkboxes in the listview?

    Hi guys,

    I am working on my listview which I have almost finish it, but i need to work on the button event to check for each string in the listview whether if the checkbox is true or false. When I tick and untick on the checkboxes to add the strings in the label, I want to know how i can check them out through on the listview to see if the checkbox is true or false?


    Here's the code:

    Code:
    private:
    String ^GetEnabledDisabledText(bool enabled)
    {
    	return ((enabled ? "Enabled" : "Disabled"));
    }
    
    static List<String^> ^subItems1 = gcnew List<String^>();
    
    void listView1_MouseClick(Object ^sender, System::Windows::Forms::MouseEventArgs ^e)
    {
    	String ^strItem = listView1::HitTest(e->Location)->Item->SubItems[1]->Text;
    
    	if (subItems1->Contains(strItem))
    	{
    	   subItems1->Remove(strItem);
    	}
    	else
    	{
    	   subItems1->Add(listView1::HitTest(e->Location)->Item->SubItems[1]->Text);
    	}
    
    	label3->Text = String::Join(", ", subItems1->ToArray());
    }
    
    void button1_Click(Object ^sender, System::EventArgs ^e)
    {
    	button1->Enabled = false;
    	array<String^> ^a = nullptr;
    	a = label3->Text->Split(',');
    	int j = 0;
    	Object ^str = GetEnabledDisabledText(listView1::Items[j]->Checked);
    	MessageBox::Show(a[j]->Trim() + " is " + str->ToString());
    }
    Do you know how I can get the messagebox to display and tells me if the checkboxes in the listview compare to each string that I add in the label is true or false?

    Can anyone help me with this?

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: How to check the checkboxes in the listview?

    What exectly is your problem here?

    I see at least two things that look at least a bit suspicious:

    • Why is subItems1 static?
    • In your button click handler you're initializing j to 0 and then use that to index listView1::Items without giving it any chance to get modified in the meantime. Is that really what you intend? BTW, shouldn't that actually be listView1->Items? I strongly doubt that this even compiles...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured