我已阅读此主题: 如何删除 ListView 中显示的特定文本/消息?
它在 winform 中工作正常(我已经测试过!)但在 WPF 中它不起作用。
我想在 listview1 中找到 firstnametxt 的文本并将其与 Firstname Column 项目进行比较,如果其为真则删除该项目(包含该项目的行)
但我不知道如何在 WPF 中处理这个问题。
我的部分代码是这样的:
XAML:
<ListView Name="listView1 HorizontalAlignment="Left" VerticalAlignment="Top" />
<ListView.View>
<GridView>
<GridViewColumn Header="FirstName" DisplayMemberBinding="{Binding Path=FirstName}" />
<GridViewColumn Header="LastName" DisplayMemberBinding="{Binding Path=LastName}" />
</GridView>
</ListView.View>
</ListView>
<TextBox Name="firstnametxt" Height="27" HorizontalAlignment="Left" Margin="271,20,0,0" VerticalAlignment="Top" Width="181" />
<Button Content="Add" Height="38" HorizontalAlignment="Left" Margin="310,242,0,0" Name="button1" VerticalAlignment="Top" Width="74" Click="button1_Click" />
<Button Content="Find" Height="38" HorizontalAlignment="Left" Name="button2" VerticalAlignment="Top" Width="74" Click="button2_Click" />
后面的代码(C#):
public class Familiy
{
public Familiy(string firstname, string lastname)
{
this.FirstName = firstname;
this.LastName = lastname;
}
private string firstname;
public string FirstName
{
get { return firstname; }
set { firstname = value; }
}
private string lastname;
public string LastName
{
get { return lastname; }
set { lastname = value; }
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
///////////////////////////
}