Solved

Changing class name of "tr" element dyncamically using IHTMLElement->put_className

Posted on 2003-12-08
4
1,346 Views
Last Modified: 2013-11-20
I want to be able to dynmically hide/unhide rows in a table. In my CDHtmlDialog class I call a function to changing the class of specific "tr" element to hidden. It appears to do that but the elements within the "tr" are still visable (buttons, text input, etc), although their text is removed. If I specify in the html file that the "tr" element is hidden innitially then everything is hidden correctly so there's nothing wrong with my html method. But I've no idea what else I can try. The html is listed below followed by


<tr id="line1">
      <td>Image 1</td>
      <td><button id="Browse">Browse 1</button></td>
      <td><input name="image1filename" type="text" readonly="true"></td>
</tr>


if (sTempTagName == _T("tr"))
{
      VARIANT varTagID;
      VariantInit(&varTagID);
      if (SUCCEEDED(pElem->getAttribute(L"id",0,&varTagID))
            && (varTagID.vt != VT_NULL))
      {
            CString strID = (CString)varTagID.bstrVal;
            if (strID == "line2")
                  pElem->put_className(L"hidden");
      }
      VariantClear(&varTagID);
}
0
Comment
Question by:wjdashwood
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:luvjd
ID: 9902658
Can u give the code which hides the tr element ? (Directly in the HTML file)
0
 

Author Comment

by:wjdashwood
ID: 9903443
Forgot to complete my last sentence. Oops! Here's the code which uses IHTMLElement->put_className to change the "tr" element  to my hidden class which is defined in my CSS file as shown at the bottom. Thanks.

if (sTempTagName == _T("tr"))
{
     VARIANT varTagID;
     VariantInit(&varTagID);
     if (SUCCEEDED(pElem->getAttribute(L"id",0,&varTagID))
          && (varTagID.vt != VT_NULL))
     {
          CString strID = (CString)varTagID.bstrVal;
          if (strID == "line2")
               pElem->put_className(L"hidden");
     }
     VariantClear(&varTagID);
}

.hidden
{
      visibility:hidden;
}
0
 
LVL 1

Accepted Solution

by:
luvjd earned 500 total points
ID: 9903722
Hi..
It seems that we have to hide the definitions ( td).. without which it is not working...
I Could get the tag name also after setting it as hidden ..but for the input elements and buttons , we have  to hide them explicitly.. normal text td's are hidden if we hide the tr...
Check the following Code...

                                      MSHTML::IHTMLDocument2Ptr pDoc(GetHtmlDocument());      
                  MSHTML::IHTMLDocument3Ptr pDoc3 = pDoc;      
                  MSHTML::IHTMLElementCollectionPtr pCollection ,pCollection1;      
            
                  MSHTML::IHTMLElementPtr pEle,pEle2;
            
                  pCollection = pDoc3->getElementsByTagName(_T("tr"));
                        pCollection1 = pDoc3->getElementsByTagName(_T("td"));
                  if(pCollection)
                  {
                        pEle = pCollection->item(CComVariant(0),CComVariant(0));
                        pEle2 = pCollection1->item(CComVariant(0),CComVariant(0));
                        //pEle->put_className(L"hidden");
                        BSTR className[10];
                        //pEle->get_className(className);
                        //pEle->setAttribute(L"class",L"hidden",2);
                        pEle->put_className(L"hidden");
                        pEle2->put_className(L"hidden");
                        pEle->get_className(className);
                        

                  }

Luv..
Jd
0
 

Author Comment

by:wjdashwood
ID: 9903747
Oh well, if that's the only way to do it then I guess it's not too bad. I'm a freak for efficiency so I would have loved to be able to hide everything with just one line of code :)

Many thanks for your help.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
dog bark java program 15 82
zeroMAx challenge 20 77
Modbus - whats the maximum I can store in one register? 4 75
Problem to picture file 3 41
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now