This project has moved. For the latest updates, please go here.

How to format a ListItem

Sep 23, 2014 at 10:17 AM
Hi,
I am adding the list to the document and then adding listitem to a list using following code
var doc = DocX.Create(fileName);
List myList = doc.AddList("", 0, ListItemType.Bulleted);
doc.AddListItem(myList, "This is a test1", 1);
doc.AddListItem(myList, "This is a test2", 1);
I wonder how to format the text added in the list?

e.g.
Current output
  • This is a test1
  • This is a test2
I want the output:
  • This is a test1
  • This is a test2
Dec 1, 2014 at 3:45 PM
Edited Dec 1, 2014 at 3:46 PM
Here is how I think you could apply the formatting. It may not be the most elegant method, but it should work.

var list1 = document.AddList("This is a test1");
document.InsertList(list1);
 foreach (var listParagraph1 in list1.Items)
 {
      listParagraph1.ReplaceText("test1", "");
      listParagraph1.Append("test1")
     .Italic()
     .Bold();
 }

 var list2 = document.AddList("This is a test2");
 document.InsertList(list2);
 foreach (var listParagraph2 in list2.Items)
 {
      listParagraph2.ReplaceText("test2", "");
      listParagraph2.Append("test2")
     .Italic()
     .Bold();
 }