July 2nd, 2012, 04:14 PM
How to check the checkboxes in the listview?
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:
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?
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->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());
Can anyone help me with this?
July 2nd, 2012, 09:10 PM
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.
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.