【发布时间】:2015-05-01 15:08:23
【问题描述】:
我正在尝试使用鼠标拖动从文本文件中获取信息的数据网格视图中选择部分数据,然后使用此选定数据更新数据网格视图。
更新:
Initial error of being unable to clear the grid view is resolved, now when the selected data is trying to be re-entered into the grid this line of text appears in the datagrid where the data should be: "DataGridViewRow { 索引=-1 }"
private void btnUpdate_Click(object sender, EventArgs e)
{
List<DataGridViewRow> rowCollection = new List<DataGridViewRow>();
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
rowCollection.Add(dataGridView1.Rows[row.Index]);
}
dataset.Tables[0].Clear();
foreach (DataGridViewRow row in rowCollection)
{
// dataGridView1.Rows.Add(row);
dataset.Tables[tableName].Rows.Add(row);
}
}
这是在datagridview中显示信息的初始代码:
foreach (string row in rows)
{
//Adds time to the array
var items = new List<string> { timeS };
items.AddRange(row.Split(delimeter.ToArray()));
speed = Convert.ToDouble(items[2]);
//converts 'speed' to a double and divides by 10 to display the correct value
speed = speed / 10;
items[2] = speed.ToString();
dataset.Tables[tableName].Rows.Add(items.ToArray());
//Adds the interval time to Dtime for each row
Dtime = Dtime.AddSeconds(inter);
}
//selects where to display the data
this.dataGridView1.DataSource = dataset.Tables[0].DefaultView;
}
任何帮助将不胜感激!
干杯。
【问题讨论】:
标签: c# datagridview datasource