添加列(列标题),以列表视图编程 [英] Add columns (column headers) to a list view programatically

查看:214
本文介绍了添加列(列标题),以列表视图编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串数组,我想这些字符串是列表视图的列(列标题或列名)。串号不知道,直到运行时和列将被编程方式添加。
基本上,我想定义多少列将在那里在列表视图中。
假设字符串中包含字符串= {STR1,STR2赛车,STR3}。
我想列表视图包含三栏分别是STR1,STR2赛车和STR3。
我想知道列表视图属性或方法,可以做添加这些。

I have an array of strings and I want these strings to be the columns(column headers or column names) of the list view. No. of strings is not known until run time and columns are to be added programmatically. Basically I want to define how many columns will be there in the list view. Suppose string contains strings = {"str1","str2","str3"}. I want the list view to contain three columns namely "str1" ,"str2" and "str3". I want to know the list view property or method that can do add these.

感谢您。

推荐答案

我不知道这是否会与列表视图中工作,但我已经这样做了网格视图,设置的AutoGenerateColumns =真正的

I'm not sure if this will work with a list view, but I've done this with a grid view, setting AutoGenerateColumns="true":

DataTable dt = new DataTable("TableName");
foreach(var col in arrayOfStrings)
    dt.Columns.Add(col);
// add rows to datatable
// of course, set the datasource of the listview/gridview
listview.DataSource = dt;
listview.DataBind();

这篇关于添加列(列标题),以列表视图编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆