如何将列复制到特定位置以及datagridview C#中的内容? [英] How to duplicate columns to particular position along with contents in datagridview C#?

查看:200
本文介绍了如何将列复制到特定位置以及datagridview C#中的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datagridview,它有4个列(A,B,C,D)。条件有时,操作员可能需要使用不同的列名称(在特定的索引位置)复制列D,但具有完全相同的内容(例如列标题文本='D'的副本)。我尝试了以下代码。



  int  lastcolidx = dataGridView3。列[  SIGNAL TYPE]。索引; 
dataGridView3.Columns.Add(dataGridView3.Columns [lastcolidx] .Clone() as DataGridViewColumn);





但是这只是在datagridview的最后位置添加新的空列,原始列内容也不会复制到新的重复列。请帮我说明怎么做



我尝试过:



  int  lastcolidx = dataGridView3.Columns [  SIGTYPE]索引。 
dataGridView3.Columns.Add(dataGridView3.Columns [lastcolidx] .Clone() as DataGridViewColumn);

DataGridViewColumn.DataPropertyName属性 [ ^ ]以指示您要在列中显示的数据。例如:

 dataGridView3.Columns.Add( new  DataGridViewColumn(){
DataPropertyName = dataGridView3.Columns [ SIGTYPE]。DataPropertyName,
...其他属性.. 。
});


Hi, I have a datagridview which has 4 number of columns(A,B,C,D). The condition is sometimes the opeartor may need to duplicate column D with a different column name(at particular index position) but with exactly the same contents(for example column header text = 'copy of D'). I have tried the below code.

int lastcolidx = dataGridView3.Columns["SIGNAL TYPE"].Index;
dataGridView3.Columns.Add(dataGridView3.Columns[lastcolidx].Clone() as DataGridViewColumn);



But this just adding the new empty column at the last position of the datagridview also the original column contents are not copied to new duplicated column. Please help me on how to do this

What I have tried:

int lastcolidx = dataGridView3.Columns["SIGTYPE"].Index;
dataGridView3.Columns.Add(dataGridView3.Columns[lastcolidx].Clone() as DataGridViewColumn);

解决方案

You also need to set DataGridViewColumn.DataPropertyName Property[^] to indicate what data you're about to show in the column. For example:

dataGridView3.Columns.Add(new DataGridViewColumn() {
   DataPropertyName = dataGridView3.Columns["SIGTYPE"].DataPropertyName,
   ... other properties...
});


这篇关于如何将列复制到特定位置以及datagridview C#中的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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