如题所示
解决方案 »
- c# winform Process问题求助
- 求一个能够自动附加数据库的小程序
- 表格中的排版问题?
- 一个字符引发的错误!~~高手请进~~速度结帖!
- 请问Vs2005中的C#是2.0吗?Vs2003中是1.0吗?
- 窗体返回值的问题,请大家帮忙
- 观点不一致,请大家来评评;WEB用户控件
- 请问哪位大侠知道在VS中如何Include文件?我要把一个字符串放到文件中,多个页面引用这个字符串。
- 请问在.NET中使用CrystalReportViewer这个控件会不会过期???我用的是CrystalReport9注册版制作的水晶报表文件
- 如何把DataTable的一行作为DataGridView的DataSource
- winform程序的边框如何换背景呢?
- [求助]插入大量数据方法
using System.Collections.Generic;
using System.Text;namespace WindowsApplication2
{
class Student
{
string _name; public string Name
{
get { return _name; }
set { _name = value; }
}
string _sex; public string Sex
{
get { return _sex; }
set { _sex = value; }
} public Student(string name, string sex)
{
this._name = name;
this._sex = sex;
}
}
}using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication2
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
} private void MainForm_Load(object sender, EventArgs e)
{
//以下步骤可以通过在dataGridView1上直接添加列自动生成
DataGridViewTextBoxColumn column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
column1.DataPropertyName = "Sex";//这里的Sex和Student类中的属性名一致
column1.HeaderText = "性别";
column1.Name = "column1";
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {column1});
Student[] list = new Student[2];//换成List<Student>也是一样的
list[0] = new Student("zhangsan", "girl");
list[1] = new Student("lisi", "boy"); this.dataGridView1.DataSource = list;
}
}
}
List<T> lists = new List<T>();
this.dataGridView1.DataSource = lists;
就是radgridview中的有三行,但都是空的。
ps:4楼MS是高手,指点下哈
{
//在界面放个datagridview然后注册Form3_Load事件就好了
List<Personnel> lps = new List<Personnel>();
lps.Add(new Personnel("XX1", 14, "男"));
lps.Add(new Personnel("XX2", 15, "男"));
lps.Add(new Personnel("XX3", 16, "男"));
lps.Add(new Personnel("XX4", 17, "女")); dataGridView1.DataSource = lps;
} public class Personnel
{
public Personnel(string name, int age, string sex)
{
this.name = name;
this.age = age;
this.sex = sex;
}
private string name; public string Name
{
get { return name; }
set { name = value; }
}
private int age; public int Age
{
get { return age; }
set { age = value; }
}
private string sex; public string Sex
{
get { return sex; }
set { sex = value; }
} }
在界面放个datagridview然后注册Form3_Load事件就好了
不用做其他的事情
里面没有AutoGenerateColumns 属性
还有
现在能显示了
但又出现个问题
就是我在radgridview中设置了三列
可出现的是六列 就是重复出现了一次
是第3方控件吗
我找到了
this.radGridView1.MasterGridViewTemplate.AutoGenerateColumns = false;
与ms的有点区别
呵呵
DataGridView是不显示内容呀
为什么呀???
datagridview.datasource=new binginglist<T>(new list<t>)刚刚遇到这个问题