首页 新闻 赞助 找找看

显示list数据到dgv

0
悬赏园豆:80 [已解决问题] 解决于 2019-04-02 13:49


得到如图的一组数据 怎么让他在DVG 上分列显示出来哇 分别是 电话 内容 时间

大哥求教的主页 大哥求教 | 初学一级 | 园豆:6
提问于:2019-04-02 10:46
< >
分享
最佳答案
0

如果值都在一个变量里,就用空格拆分,然后绑定到对应列里

收获园豆:40
ifz | 菜鸟二级 |园豆:302 | 2019-04-02 10:56

这个方法我试过 但是一直报错 能否远程给看看

大哥求教 | 园豆:6 (初学一级) | 2019-04-02 11:00

@大哥求教: 发你了

ifz | 园豆:302 (菜鸟二级) | 2019-04-02 11:03

@220✈: 什么?

大哥求教 | 园豆:6 (初学一级) | 2019-04-02 11:04

@大哥求教: 发你博客园信箱了

ifz | 园豆:302 (菜鸟二级) | 2019-04-02 11:06
其他回答(1)
0

你看看,dataGridView1 设置一下 DataPropertyName 属性,绑定这三个字段:

using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WinForm
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();

            List<string> drTypeList = new List<string>
            {
                "123 百度:www 2019/4/2 10:16:04",
                "765 百度:www 2019/4/2 10:16:04",
            };
            drTypeList = drTypeList.Distinct().ToList();

            Model model;
            List<Model> lst = new List<Model>();
            foreach (var item in drTypeList)
            {
                string[] strArr = item.Split(' ');
                model = new Model();
                model.tel = strArr[0];
                model.content = strArr[1];
                model.time = strArr[2] + " " + strArr[3];
                lst.Add(model);
            }
            dataGridView1.DataSource = lst;
        }
    }

    class Model
    {
        public string tel { get; set; }
        public string content { get; set; }
        public string time { get; set; }
    }
}
收获园豆:40
三人乐乐 | 园豆:4819 (老鸟四级) | 2019-04-02 11:17

强得一匹

支持(0) 反对(0) 大哥求教 | 园豆:6 (初学一级) | 2019-04-02 11:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册