Solved

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

Posted on 2003-12-08
4
1,379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wordcount challenge 11 163
Problem to event 3 123
Problem to App source 6 120
How do I get Window Title of all opened process? 4 61
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

734 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