0

I had a marquetool for my winform Application I obtained it from here

And I that control I can Add Textelement By using the below code

MarqueControl.Entity.TextElement textElement1 = 
    new MarqueControl.Entity.TextElement("TextElement 1");
MarqueControl.Entity.TextElement textElement2 = 
    new MarqueControl.Entity.TextElement("TextElement 2");
MarqueControl.Entity.TextElement textElement3 = 
    new MarqueControl.Entity.TextElement("TextElement 3");
superMarquee1.Elements.AddRange(new MarqueControl.Entity.TextElement[] 
               {
                   textElement1,
                   textElement2,
                   textElement3
               }

but the issue is I had to fill the textelement from datatable , I did it like this

   for(int i=0;i<dt.Rows.Count ;i++){
                String wholetext = dt.Rows[i][1].ToString() + "--" + dt.Rows[i][1].ToString();
            //    String textElement="textElement"+i.ToString();

                TextElement element = new TextElement(wholetext);

                MarqueControl.Entity.TextElement textElement1 = 
    new MarqueControl.Entity.TextElement("wholetext");
            }

The issue is every time the same text textelemt is getting updated . means It will be solved only when I can make different identifier for the text element. Can Anyone suggest how to change the varaibale name inside a loop

1
  • 1
    Maybe you should use an array or a <List> of Marquee-Elements and iterate through this list in your "update" code. Then you don't have to call them by their variable names but their indexes. Plus you have a compact handle for all the Marquee Elements, too. Commented May 13, 2013 at 12:53

2 Answers 2

1
// creation
var marqueeList = new List<MarqueControl.Entity.TextElement>();

for (int i = 1; i<=3; i++)
{
  marqueeList.Add(new MarqueControl.Entity.TextElement("TextElement "+i));
}

// usage
for(int i=0;i<dt.Rows.Count ;i++)
{
  String wholetext = [here is your retrieving code];
  marqueeList[0] = new MarqueControl.Entity.TextElement(wholetext); // 0 = first item
  // OR:
  marqueeList[i] = new MarqueControl.Entity.TextElement(wholetext);
}
Sign up to request clarification or add additional context in comments.

2 Comments

it is working perfectly but I added one more line atlast superMarquee1.Elements.AddRange(marqueeList.ToArray());
Yes, of course - I forgot the line where you use your objects at last. :)
0

I'm not sure it's that you try to do but can you try this ?

List<TextElement> list = new List<TextElement>();
for(int i = 0; i < dt.Rows.Count; i++)
{
    String wholetext = dt.Rows[i][1].ToString() + "--" + dt.Rows[i][1].ToString();

    list.Add(new TextElement(wholetext));
 }
 superMarquee1.Elements.AddRange(list.ToArray());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.