Reputation: 95
I have a listview control and the text will not show up. I have tried 3 different implementations and I get the same result in each. The rows for the associated number of items will highlight, but the text is nowhere. I am using WPF and the text contents look like the following in the file I am reading in:
string1::string2
However, for testing purposes, I am not utilizing the file contents.
Tutorial I'm Using: http://www.wpf-tutorial.com/listview-control/listview-with-gridview/
"1" and "2" were in there just to test.
List<ServerData> items = new List<ServerData>();
while ((line = file.ReadLine()) != null )
{
string[] serverData = Regex.Split(line, "::");
items.Add(new ServerData() { IPAddress="1", ServerName="2" });
}
listServer.ItemsSource = items;
file.Close();
....
public class ServerData
{
public string IPAddress { get; set; }
public string ServerName { get; set; }
}
<ListView Margin="10,47,11,45.8" x:Name="listServer" Grid.RowSpan="2">
<ListView.View>
<GridView>
<GridViewColumn Header="IP Address" Width="218.4" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Header="Server Name" Width="218.4" DisplayMemberBinding="{Binding Name}" />
</GridView>
</ListView.View>
</ListView>
Upvotes: 1
Views: 365
Reputation: 6220
<ListView Margin="10,47,11,45.8" x:Name="listServer" Grid.RowSpan="2">
<ListView.View>
<GridView>
<GridViewColumn Header="IP Address" Width="218.4" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Header="Server Name" Width="218.4" DisplayMemberBinding="{Binding Name}" />
</GridView>
</ListView.View>
</ListView>
Here's your problem, you're binding the columns to Name
, when instead it should be:
<ListView Margin="10,47,11,45.8" x:Name="listServer" Grid.RowSpan="2">
<ListView.View>
<GridView>
<GridViewColumn Header="IP Address" Width="218.4" DisplayMemberBinding="{Binding IPAddress}" />
<GridViewColumn Header="Server Name" Width="218.4" DisplayMemberBinding="{Binding ServerName}" />
</GridView>
</ListView.View>
</ListView>
Upvotes: 1