C# Listview 数据绑定


今天搞Winform,有串数据需要绑定到TabControl里面,原来用datatable,组长说这玩意会有问题不让用,菜鸟实在不会,百度查的Listview用法,写了个数组进去绑定

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            string[,] numbers = new string [,] { { "1"," 2" ," 3"},  {" 4", "5", "6 "} };
            
            for (int i = 0; i < numbers.GetLength(0); i++)
            {
                
                    ListViewItem additem = new ListViewItem();
                    additem.SubItems.Clear();
                    additem.SubItems.Add(numbers[i,0]);
                    additem.SubItems.Add(numbers[i,1]);
                    additem.SubItems.Add(numbers[i,2]);
                    listView1.Items.Add(additem);
                    additem.EnsureVisible();
                    
            } 
        }
    }
}

  数据是绑进去了,就是错位啊,我滴爹爹

原因好像是这玩意默认从1开始的。怎么解决,还未知。

 

 

方法二:

ListViewItem cj;

cj = new ListViewItem(numbers[i, 0]);
cj.SubItems.Add(numbers[i, 1]);
cj.SubItems.Add(numbers[i,2]);
listView1.Items.Add(cj);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM