wpf ListView自动序号,默认的序号字段

Posted 棉晗榜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了wpf ListView自动序号,默认的序号字段相关的知识,希望对你有一定的参考价值。

前端页面test.xaml

<Window x:Class="WpfSnqkGasAnalysis.WindowGasStepLog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfSnqkGasAnalysis"
        mc:Ignorable="d"
        Title="日志" Height="400" Width="640" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen">
    <Window.Resources>
        <local:ItemIndexConvert x:Key="itemIndex"></local:ItemIndexConvert>
    </Window.Resources>
    <Grid>
        <ListView x:Name="listView"  ItemsSource="Binding  "  Style="StaticResource ListView1" >
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="序号" DisplayMemberBinding ="Binding  Converter=StaticResource itemIndex" />
                    <GridViewColumn Header="时间" DisplayMemberBinding ="Binding Check_time"/>
                    <GridViewColumn Header="状态" DisplayMemberBinding ="Binding E3" />
                    <GridViewColumn Header="操作人" DisplayMemberBinding ="Binding Check_user_name" />
                    <!--<GridViewColumn Header="操作" DisplayMemberBinding ="Binding Number" />-->
                </GridView>
            </ListView.View>
        </ListView>

    </Grid>
</Window>

后台页面

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using WpfSnqkGasAnalysis.Model;

namespace WpfSnqkGasAnalysis

    /// <summary>
    /// 实现显示数据,序号
    /// </summary>
    /// 创建时间:2022-12-12 14:18:15。 
    internal class ItemIndexConvert : IValueConverter
    
        public int Index = 0;

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        
            ++Index;
            return Index;
        

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        
            throw new NotImplementedException();
        
    


using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfSnqkGasAnalysis.Model;
using WpfSnqkGasAnalysis.IBusiness_impl;

namespace WpfSnqkGasAnalysis

    /// <summary>
    /// 查看气数据操作日志
    /// </summary>
    /// 创建时间:2022-12-12 13:55:37。 
    public partial class WindowGasStepLog : Window
    
        public WindowGasStepLog()
        
            InitializeComponent();
        

        /// <summary>
        /// 点击的数据主键
        /// </summary>
        internal long gasKey;

       public ObservableCollection<Gas_check_history> HistoryList  get; set; 

        private void Window_Loaded(object sender, RoutedEventArgs e)
        
            HistoryList=new ObservableCollection<Gas_check_history>();
            Gas_analysisBusiness buss = new Gas_analysisBusiness();
            var list = buss.GetStepLog(gasKey);
            list.ForEach(item =>
            
                HistoryList.Add(item);
            );
            listView.ItemsSource = HistoryList;
        
    


以上是关于wpf ListView自动序号,默认的序号字段的主要内容,如果未能解决你的问题,请参考以下文章

mysql中如何设置一个字段,表中每增加一个值,这个字段自动产生一个连续的序号?

怎样在SQl数据库的表格里添加“序号”表示字段

sql 查询语句自动增加序号

怎么用sql对搜索结果排序并添加序号

mysql在查询结果中自动添加序号字段列

mysql在查询结果中自动添加序号字段列