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

    how to tick each checkbox in the listview?

    Hi guys,

    I need your urgently help. I have extract each strings from mystrings to input them in the listview. Now I want to know how i can tick the checkboxes for each array in the listview when i'm checking for each "enabled" strings in the php source on each line?

    Here's the code:

    Code:
    System::Void Form1::timer1_Tick(System::Object^  sender, System::EventArgs^  e)
    {
        timer1->Enabled = false;
        timer1::Stop();
    
        try
        {
            String ^URL1 = "http://www.mysite.com/myscript.php?user=test&pass=test";
            HttpWebRequest ^request1 = safe_cast<HttpWebRequest^>(WebRequest::Create(URL1));
            HttpWebResponse ^response1 = safe_cast<HttpWebResponse^>(request1->GetResponse());
            StreamReader ^reader1 = gcnew StreamReader(response1->GetResponseStream());
            String ^str1 = reader1->ReadToEnd();
            String ^pattern1 = "(<p id='mystrings1'>(.*?)</p>(.*?)<span id=\"mystrings2\">Enabled</td>)";
            MatchCollection ^matches1 = Regex::Matches(str1, pattern1);
    
            for each (Match ^x1 in matches1)
            {
                array<String^> ^StrArr1 = x1->Value->ToString()->Split();
                Listview1::Items->Add(x1->ToString());
            }
        }
        catch (Exception ^ex)
        {
        }
    }

    If you do know how to do this, I will be very grateful.

    Thanks,
    Mark

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

    Re: how to tick each checkbox in the listview?

    Quote Originally Posted by mark103 View Post
    [...] Now I want to know how i can tick the checkboxes for each array in the listview when i'm checking for each "enabled" strings in the php source on each line?
    You can't, by definition: A list view contains list view items, not arrays.

    If you'd want to check some of those list view items, however, you may set their Checked properties to true. Of course that would only have any (observable) effect if the list view's CheckBoxes property is set to true as well.
    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.

  3. #3
    Join Date
    Aug 2007
    Posts
    448

    Re: how to tick each checkbox in the listview?

    thanks for the help Eri523. Can you please help me how to tick the checkboxes for each listviewitem in the listview when I find each strings from the php source called "enabled" while the strings are on the same line as the strings, e.g the "enabled" strings is on the same line as the "my strings 2 what ever it is". I'd hope you get this.



    here's the current code:

    Code:
    System::Void Form1::timer1_Tick(System::Object^  sender, System::EventArgs^  e)
    {
        timer1->Enabled = false;
        timer1::Stop();
    
        try
        {
            String ^URL1 = "http://www.mysite.com/myscript.php?user=test&pass=test";
    	HttpWebRequest ^request1 = safe_cast<HttpWebRequest^>(WebRequest::Create(URL1));
    	HttpWebResponse ^response1 = safe_cast<HttpWebResponse^>(request1->GetResponse());
    	StreamReader ^reader1 = gcnew StreamReader(response1->GetResponseStream());
    	String ^str1 = reader1->ReadToEnd();
    	String ^pattern1 = "(<p id='mystrings1'>(.*?)</p>)";
    	MatchCollection ^matches1 = Regex::Matches(str1, pattern1);
    
    	for each (Match ^x1 in matches1)
    	{
    		ListViewItem ^item1 = gcnew ListViewItem("",1);
    		item1->SubItems->Add(x1->Value->ToString()->Replace("<p id='mystrings1'>", "")->Replace("</p>", ""));
    		listView1::Items->AddRange(gcnew array<ListViewItem^>{item1});
    		listView1->CheckBoxes = true;
    	}
        }
        catch (Exception ^ex)
        {
        }
    }

    If you know how to tick the checkboxes for each listviewitem in the listview on the same line as the "enabled" strings, i would be very grateful.

    if you aren't sure what i means then take a look on the screenshot and get back to me if you get it.

    php page
    http://img840.imageshack.us/img840/7051/phppage.jpg


    my listview
    http://img819.imageshack.us/img819/133/listview.jpg



    hope you can be able to help me with this.

    Thanks,
    Mark

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

    Re: how to tick each checkbox in the listview?

    Right now I'm working on a project that uses a list view with state images, and (curently) it's 11 possible state images (and consequentially item states), so I think it should be obvious that simply setting the ListView::CheckBoxes property to true and successfully hoping for the .NET framework to do all the rest for me is highly unlikely. Consequentially, at least in my own app I'm talking about here, I need to catch state image clicks myself and also manage state transitions myself, that, at leat most of the time, are somewhat more complex than simply checking or unchecking a check box.

    I'm somewhat embarrassed to say that at all, but in order to avoid some anticipatable problems in the first place, you are aware that setting the ListView::CheckBoxes property to true does not instantly check all the check boxes of all the items in the list view; it merely arranges that there are check boxes displayed next to the items at all in the first place. Aren't you? The checked/unchecked state of each item is controlled by its ListViewItem::Cecked property instead.

    In case all the above still doesn't help you to solve the problem, it would (as has been stated so many times around the forum here) probably best to post a complete compilable project (or at least some code that could easily be implanted into a blank project for testing) to reproduce the actual problem you're encountering (and that not even comes across completely clear from your human-verbal description).

    If you'd really want a chance of anyone around here actually checking out the code you provided, you'd probably at least need to make sure that the code you post does not...
    • depend on any of your local code we don't have any idea of here,
    • depend on any user input which is even more difcult to anticipate for us, since we have no idea of what your app acually is about and what users may or may not enter and how to potentially react to that,
    • deped on any remote websites of uncertain reputation, that probaly few people around here would even try to connect to in good faith - in case they actually were real websites: The addresses in your code snippets rather look like dummies...
    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