本帖最后由 dapsjj 于 2016-11-30 10:43 编辑
spread显示的内容是循环dataset放进去的,放进spread后,spread使用grdMain.ActiveSheet.DataSource = m_rsDirect;去绑定数据源,然后修改了spread中的一些值,点击一个按钮,去调试spread的值发生变化后,dataset的对应值有没有发生变化,结果发现dataset的对应的值没有发生改变,调试的代码为:- private void displayData()
- {
- m_rsDirect = GetThroughDirectionDataForCorrectDirection(m_intBin, m_strProdCode);//执行存储过程获取结果集
- if (m_rsDirect == null)
- {
- grdMain.ActiveSheet.ClearRange(0, 0, grdMain.ActiveSheet.RowCount, grdMain.ActiveSheet.ColumnCount, false);
- grdMain.ActiveSheet.Cells[0, 0, grdMain.ActiveSheet.RowCount - 1, grdMain.ActiveSheet.ColumnCount - 1].Locked = true;
- MessageBox.Show("无数据!");
- }
- else
- {
- grdMain.ActiveSheet.DataSource = m_rsDirect;//grdMain绑定数据源
- setGrdMainSpreadData(m_rsDirect.Tables[0]);//数据放入spread
- }
- }
-
- private void setGrdMainSpreadData(DataTable spdt)
- {
- if (this.grdMain.ActiveSheet.RowCount > 0)
- {
- this.grdMain.ActiveSheet.Rows.Count = 0;
- }
- this.grdMain.ActiveSheet.Rows.Count = spdt.Rows.Count;
- DataRowCollection rows = spdt.Rows;
- int rowCount = rows.Count;
- int nowRow = 0;
- for (int i = 0; i < rowCount; i++)
- {
- grdMain.ActiveSheet.Cells[nowRow, 0].Value = rows[i]["店CD"].ToString();
- grdMain.ActiveSheet.Cells[nowRow, 1].Value = rows[i]["店名称"].ToString();
- grdMain.ActiveSheet.Cells[nowRow, 2].Value = rows[i]["No"].ToString();
- grdMain.ActiveSheet.Cells[nowRow, 3].Value = rows[i]["数量"].ToString();
- grdMain.ActiveSheet.Cells[nowRow, 4].Value = rows[i]["重量"].ToString();
- nowRow++;
- }
- }
- private void btnDecide_Click(object sender, EventArgs e)
- //到这个方法调试数据的时候发现spread的值改变后,dataset的对应的值无变化
- {
-
- foreach (DataRow row in m_rsDirect.Tables[0].Rows)
- {
- foreach (DataColumn mDc in m_rsDirect.Tables[0].Columns)
- {
- string a = row[mDc].ToString();
- }
- }
- }
-
复制代码
请问为啥datdset的值没有随着spread的变化而变化呢?
|
|