【问题标题】:i want to read dataGrid line by line in wpf using c#我想使用 c# 在 wpf 中逐行读取 dataGrid
【发布时间】:2018-07-19 04:56:58
【问题描述】:
Workbook workbook = new Workbook();
workbook.LoadFromFile(FileNameDb);
Worksheet sheet = workbook.Worksheets[0];
DataTable dataTable = sheet.ExportDataTable();
DataView view = new DataView(dataTable);
dataGridView1.ItemsSource = view;

string str;
for (int i = 0; i < dataGridView1.Items.Count - 1; i ++)
{
str = "Insert Into Sample(MCC, MNC, LAC, CellId, CellIdAddress, LAT, LONG, Network) 
                   Values(" + dataGridView1.Rows[i].Cells[0].Value.ToString() + ", '" + 
                              dataGridView1.Rows[i].Cells[1].Value.ToString() + "'," + 
                              dataGridView1.Rows[i].Cells[2].Value.ToString() + "," + 
                              dataGridView1.Rows[i].Cells[3].Value.ToString() + "," + 
                              dataGridView1.Rows[i].Cells[4].Value.ToString() + "," + 
                              dataGridView1.Rows[i].Cells[5].Value.ToString() + "," + 
                              dataGridView1.Rows[i].Cells[6].Value.ToString() + "," + 
                              dataGridView1.Rows[i].Cells[7].Value.ToString() + ")";
    command = new SQLiteCommand(str, m_dbConnection);
    command.ExecuteNonQuery();
}

但是这里的行给我错误数据网格不包含行的定义 并在阅读每一行后将该行添加到 sqlite 数据库中

【问题讨论】:

  • 请帮我解决这个问题

标签: c# xml


【解决方案1】:

希望下面的代码可以工作

foreach (DataGridCellInfo di in dgDataGrid.SelectedCells) 
{
    DataRowView dvr = (DataRowView)di.Item;

    MessageBox.Show(dvr[1].ToString()); 
}

【讨论】:

【解决方案2】:

像在数据网格上使用循环

for(int i = 0; i

【讨论】:

  • 这只是一个示例,如果您将 wpf 网格控件与列表绑定 具有属性名称、地址、位置,那么您可以按行访问名称。在这种情况下,您的对象将是客户
猜你喜欢
  • 2019-04-12
  • 2021-12-26
  • 2022-01-25
  • 2011-12-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多