从DataGridView读取列,并将其放置在一个字符串数组 [英] Read column from dataGridView and place it in a string array

查看:152
本文介绍了从DataGridView读取列,并将其放置在一个字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGridView,其中第一列是固定的,具有文本框。第二列组合框。所有在第二列中的行的有4个选择(姓名,地址,日期)。

当用户从组合框选择和presses一个按钮,我需要第二列的值,并把它们放到一个新的的String []

因此​​,如果用户选择

 名称,
姓,
名称,
日期,

它们被放在一个名为字符串数组 FromDataGrid [] 。至于现在,我已经取得这样的:

 私人无效button2_Click(对象发件人,EventArgs的发送){
    字符串[] = COLB新的字符串[dataGridView1.Rows.Count]


解决方案

类似的东西:

 的for(int i = 0; I< dataGridView1.Rows.Count;我++)
    COLB [I] = Convert.ToString(da​​taGridView1.Rows [I] .Cells [1]。价值);

I have a DatagridView in which the first column is fixed and has TextBoxes. The second column has ComboBoxes. All of the rows at the second column have 4 choices(name, surname, address, date).

When the user chooses from the ComboBoxes and presses a button, I need to take the values of the second column and put them in a new string[].

So if the user chooses :

name,
surname,
name,
date,

They are put in a string array named FromDataGrid[]. As far as now I have made this:

private void button2_Click(object sender, EventArgs e) {
    string[] colB = new string[dataGridView1.Rows.Count];

解决方案

Something like that:

for (int i = 0; i < dataGridView1.Rows.Count; i++)
    colB[i] = Convert.ToString(dataGridView1.Rows[i].Cells[1].Value);

这篇关于从DataGridView读取列,并将其放置在一个字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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