0

我让这个项目为自己保持秩序。

我所拥有的是:

+---Date---+----Time----+----Error-----------+
|24-24-2012|    4:42    | Warning - test/test|
+----------+------------+--------------------+

现在我得到了所有的工作,至少阅读和写作。但它并没有像我希望的那样进行。

我希望这些文本像:

Date (items.add)
time (subitem)
error (subitem)

我希望它写成:

date | time | error

然后一旦程序读取它,他就知道:

| = Start of subitem ( || end of subitem )

所以它在要写入的文本文件中的样子是:

date | time ||| error || ( which means : time start+end / error start+end (add to subitem)

我想让程序视觉工作室知道他知道( | 1x = subitems.add(" - And | 2x = ");

很难解释。我会尝试不那么复杂的。

| = subitems.add("<br>
|| = ");

所以写一个文件看起来像:

writer.writeline( | + "hello" + || + | + "test" + || );

这将导致文本文件为:

| hello ||| test ||

一旦程序启动,它将以这种方式再次读取它:

Listview.additems.add( hello ) *with no | or ||*

测试将是:

listview.subitem( test ) *with no | or ||*

等等...


对于像我这样的自闭症患者来说,截图可以更好地解释它。

点击这里查看屏幕截图

4

2 回答 2

0

我不确定我是否完全理解您需要实现的目标,但我认为您希望列表框中的每个项目都遵循特定的模板 - 所以主要的项目将在某个 X 模板中,并且子项目将有一个不同的模板 - 有点有意。因此,当根据您要添加的项目类型添加到列表框时,设置

listboxitem.template = isSubitem?subItemTemplate:mainItemTemplate;

这就是我从你的问题中了解到的全部内容。希望这是有道理的。

于 2012-07-24T03:24:54.170 回答
0

因此,将响应添加为另一个答案。您的代码将如下所示:

using(StreamReader reader = new StreamReader(logFileName))
{
  StringBuilder currentItem = new StringBuilder();
  char currentChar;
  while (true)
  {
    if (reader.Peek() == 'specialChar')
    {
      if (currentChar == '|')
      {
        // This indicates that the currentItem is subItem
        AddNewSubitem(currentItem.ToString());
      }
      else
      {
        AddNewItem(currentItem.ToString());
      }
      currentItem.Clear();
      reader.Read();
    }
    else if (reader.Peek() != null)
    {
      curentItem.Append(reader.Read());
    }
    else
    {
      break;
    }
  }
}
于 2012-07-24T04:10:15.240 回答