添加Data GridView Button Column。
具体代码如下:
public Form1()
{
InitializeComponent()
this.Load += new EventHandler(Form1_Load)
}
List<string>strSourec = new List<string>{ "1", "2" }
void Form1_Load(object sender, EventArgs e)
{
foreach (string item in strSourec)
{
DataGridViewButtonColumn Column1 = new DataGridViewButtonColumn()
Column1.HeaderText = item
this.dataGridView1.Columns.Add(Column1)
}
DataGridViewRow dr = new DataGridViewRow()
for (int i = 0i <strSourec.Counti++)
{
DataGridViewButtonCell dgvbc = new DataGridViewButtonCell()
dgvbc.Value = strSourec[i]
dr.Cells.Add(dgvbc)
public Form1(){
InitializeComponent()
this.Load += new EventHandler(Form1_Load)
}
List<string>strSourec = new List<string>{ "1", "2" }
void Form1_Load(object sender, EventArgs e)
{
foreach (string item in strSourec)
{
DataGridViewButtonColumn Column1 = new DataGridViewButtonColumn()
Column1.HeaderText = item
this.dataGridView1.Columns.Add(Column1)
}
DataGridViewRow dr = new DataGridViewRow()
for (int i = 0i <strSourec.Counti++)
{
DataGridViewButtonCell dgvbc = new DataGridViewButtonCell()
dgvbc.Value = strSourec[i]
dr.Cells.Add(dgvbc)
}
dataGridView1.Rows.Add(dr)
this.dataGridView1.CellMouseDown += new DataGridViewCellMouseEventHandler(dataGridView1_CellMouseDown)
}
void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (dataGridView1[e.ColumnIndex, e.RowIndex].Value == null) return
MessageBox.Show(dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString())
}
你用gridview想实现这样的功能,如果你不在意页面回传刷新。每次当你点击"+"时,你在后台代码中把你的数据源的顺序重新调整,然后重新绑定。可以实现这样的功能。
还有一种方法就是用脚本。gridview最终呈现的也是table,你用脚本控制你点击的某一样,然后重组tr,这样页面不会发生回传。但是如果要保存你修改后的顺序。还要麻烦一些。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)