Solved

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

Posted on 2003-12-08
4
1,362 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Line meaning 9 85
use of cookies and regulations 1 86
Path of Workbook 3 76
API Soap Calls 4 112
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…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

776 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