如何检索多列列表视图中的第一个值

本文关键字:视图 列表 第一个 何检索 检索 | 更新日期: 2023-09-27 17:52:15

这里是XAML中的listview元素

 <ListView x:Name="jobsListView_manageajob" HorizontalAlignment="Left" Height="488" Margin="39,163,0,0" VerticalAlignment="Top" Width="215" FontSize="15" BorderThickness="0" SelectionChanged="jobsListView_manageajob_SelectionChanged">
        <ListView.Resources>
            <Style TargetType="GridViewColumnHeader">
                <Setter Property="Visibility" Value="Collapsed" />
            </Style>
        </ListView.Resources>
        <ListView.View>
            <GridView AllowsColumnReorder="False">
                <GridViewColumn DisplayMemberBinding="{Binding JobNumberListView1}" Width="50"/>
                <GridViewColumn DisplayMemberBinding="{Binding JobNameListView1}"/>
            </GridView>
        </ListView.View>
    </ListView>

我只需要从一行中检索当前选中的项

private void jobsListView_manageajob_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
          searchTextBox_manageajob.Text = Convert.ToString(jobsListView_manageajob.SelectedItem);
    }
任何帮助都是非常感激的,我被困住了!

如何检索多列列表视图中的第一个值

尝试将所选项目对象强制转换为实际的模型类型,然后获取其感兴趣的属性:

var myModel = (ClassName)jobsListView_manageajob.SelectedItem;
searchTextBox_manageajob.Text = myModel.JobNameListView1;