Coffeehouse Thread

12 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Formatting HTML in list view

Back to Forum: Coffeehouse
  • User profile image
    Steve411

    Working on a small pretty important project tonight, but im wondering, is there any way to replace HTML formating with a string in list boxes? What i am doing at the moment is looping through the items real quickly and replacing them like so.


    for (int i = 0; i < ListViews.Items.Count; i++)
    {
    ListViews.Items[i].ToolTipText.Replace("&quot;", "'");
    ListViews.Items[i].ToolTipText.Replace("<br>", Environment.NewLine);
    ListViews.Items[i].ToolTipText.Replace("<br>", Environment.NewLine);
    ListViews.Items[i].ToolTipText.Replace("<P>", Environment.NewLine);
    ListViews.Items[i].ToolTipText.Replace("&nbsp;", " ");
    }

    Apperantly that code does not find and replace the <br> tags. How come?
    [note that everything else is replaced]

  • User profile image
    ZippyV

    Coding question should be posted in Techoff.


    Within your loop you're not specifying which item. Like euh, ...Items.Item[i].TooltipText... something like this.

  • User profile image
    Steve411

    ZippyV wrote:
    Coding question should be posted in Techoff.


    Within your loop you're not specifying which item. Like euh, ...Items.Item.TooltipText... something like this.

    i is the item since it inherits the index of each item in the list view as they are being added. as i said, only the <br> tag is not being replaced, everything else in that code is functioning.
    and sorry about the techoff mistake, used to the coffeehouse

  • User profile image
    MikeGoatly

    I know it's kind of a daft answer, but is the case of the <br> is correct? (I.e. is it <BR> in the text you're replacing?)

    EDIT: The only reason I mention this is the casing of the <P> tag is different...

  • User profile image
    W3bbo

    WebStandardsMan to the rescue once again...

    Okay.. I can't help you directly, but here are some free pointers:

    a) All elements (aka "tags") have to be in lower case:

    <p></p> not <P></P>

    b) properly formed:

    <br /> not <BR>

    b) Only use <br /> in things like <pre>, <code>, and <p> for manual line breaks in the document text. Not for things like separating paragraphs or spacing between blocks, that's what <p> and margin-top:; (respectivly) is for.

    HTH
    -WebStandardsMan

  • User profile image
    Steve411

    W3bbo wrote:
    WebStandardsMan to the rescue once again...

    Okay.. I can't help you directly, but here are some free pointers:

    a) All elements (aka "tags") have to be in lower case:

    <p></p> not <P></P>

    b) properly formed:

    <br /> not <BR>

    b) Only use <br /> in things like <pre>, <code>, and <p> for manual line breaks in the document text. Not for things like separating paragraphs or spacing between blocks, that's what <p> and margin-top:; (respectivly) is for.

    HTH
    -WebStandardsMan

    Thanks guys. One thing though, the <br> || <br /> are appearing in tooltip for each item. i do not place them there. I am trying to remove them as i see them, some are <br> some are <br />.

  • User profile image
    Steve411

    MikeGoatly wrote:
    I know it's kind of a daft answer, but is the case of the <br> is correct? (I.e. is it <BR> in the text you're replacing?)

    EDIT: The only reason I mention this is the casing of the <P> tag is different...

    depends on the tooltip being displayed, some are <BR> some are <br>, some are even <P> <p>.. lower + upper case.

  • User profile image
    sbc

    I think you are doing the replace wrong. I think replace is case insensitive, so it shouldn't matter if it is <br> <BR> <bR> or <Br>.

    ListViews.Items[i].ToolTipText = ListViews.Items[i].ToolTipText.Replace("&quot;", "'");

  • User profile image
    Steve411

    sbc wrote:
    I think you are doing the replace wrong. I think replace is case insensitive, so it shouldn't matter if it is <br> <BR> <bR> or <Br>.


    ListViews.Items[i].ToolTipText = ListViews.Items[i].ToolTipText.Replace("&quot;", "'");
     


    as i said, Wink every other replacement works, just not the <br> values. Wink

  • User profile image
    Sven Groot

    Sbc is right about needing the assignment, however Replace is case sensitive.

  • User profile image
    sbc

    Perhaps try using Regex.Replace:

    ListViews.Items[i].ToolTipText = Regex.Replace(ListViews.Items[i].ToolTipText, "<br>", Environment.NewLine, RegexOptions.IgnoreCase);

  • User profile image
    Steve411

    sbc wrote:
    Perhaps try using Regex.Replace:

    ListViews.Items[i].ToolTipText = Regex.Replace(ListViews.Items[i].ToolTipText, "<br>", Environment.NewLine, RegexOptions.IgnoreCase);
     


    Hm I tried that. It adds the Tooltip text values into the list view items self. [first category] Thank you everyone

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.