在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
今天搞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]); |
请发表评论