如果这是重复,我很抱歉,但我在这里搜索了谷歌,所有内容都提供了较旧的代码。
我创建了一个包含2列的ListView。我正在尝试将项目添加到ListView。我的代码:
for (intDisplayCnt = 0; intDisplayCnt < intFieldLengths.Length; intDisplayCnt++)
{
string[] strRow = { "Field" + (intDisplayCnt + 1), intFieldLengths[intDisplayCnt].ToString() };
//aryListItems[0, 0] = "Field" + (intDisplayCnt + 1);
//aryListItems[0, 1] = intFieldLengths[intDisplayCnt].ToString();
//ListViewItem.
lvwFieldInfo.Items.Add(strRow);
}
代码执行但输出为String [] Array String [] Array
非常感谢任何帮助!
谢谢, 肯特
答案 0 :(得分:0)
不确定您为ListView使用的XAML代码。但您可以考虑查看下面的示例,看看它是否符合您的要求。
// xmal code
<ListView x:Name="listView">
<ListView.View>
<GridView>
<GridViewColumn Header="FieldId" DisplayMemberBinding="{Binding FieldId}"/>
<GridViewColumn Header="FieldLength" DisplayMemberBinding="{Binding FieldLength}"/>
</GridView>
</ListView.View>
</ListView>
// define your custom listview item class
public class MyFieldListViewItem
{
public string FieldId { get; set; }
public string FieldLength { get; set; }
}
// when adding the item
for (intDisplayCnt = 0; intDisplayCnt < intFieldLengths.Length; intDisplayCnt++)
{
var fieldId = "Field" + (intDisplayCnt + 1);
var fieldLen = intFieldLengths[intDisplayCnt].ToString();
lvwFieldInfo.Items.Add(new MyFieldListViewItem { FieldId = fieldId, FieldLength = fieldLen });
}