如何映射我的输入数据

时间:2014-10-15 05:30:25

标签: c# asp.net c#-4.0 datagridview c#-3.0

我的输入字符串是VALVE,GATE,SH_NAME:VLV,GATE,VLV_NOM_SIZE:4-1/16IN

我想要这样的输出(我希望在datagridview中输出)

COLUMN_1              COLUMN_2
 VALVE
 GATE
 SH_NAME                VLV
 GATE            
 VLV_NOM_SIZE           4-1/16IN

1 个答案:

答案 0 :(得分:2)

代码

string str = "VALVE,GATE,SH_NAME:VLV,GATE,VLV_NOM_SIZE:4-1/16IN";
string[] Rows = str.Split(',');
dataGridView1.Columns.Add("Column1", "Column1");
dataGridView1.Columns.Add("Column2", "Column2");
foreach (string AddRow in Rows)
{
   string[] Row = AddRow.Split(':');
   dataGridView1.Rows.Add(Row);
}