如果你想使用「提交」按鈕來保存新的股票更正,那麼 的做法將是:
- 創建與產品名稱和空單元格的股票校正
一個DataGridView - 後「提交」按鈕被點擊閱讀「更正」列中的值,如果值存在更新數據庫...
在這裏你可以怎麼做它:
在設計師dgvProductCorrections
創建一個DataGridView, 然後設計師在此datagridview的 dgvProductCorrection_Product
和dgvProductCorrection_Correction
創建兩列。 將這個(或)在列,請將.Name屬性
然後,我假定你有一類產品,其中存在的屬性,請將.Name列名, 你將需要把這個屬性的名稱(在我的例子將名稱)在.DataProperty列
以上可以與設計師或代碼(構造函數)
添加列表產品List<Product> lstProducts;
中的datagridview會像做:
dgvProductCorrections.DataSource = lstProducts; //(this may be in Form_Load)
Rememeber添加列表前一個DataGridView屬性AutoGenerateColumns
設置爲False
dgvProductCorrections.AutoGenerateColumns = false;
在您提交按鈕的Button_Click
事件處理程序放在哪裏,你通過所有的行和讀修正值loopin代碼。之後,您可以使用這些值更新數據庫
//Code in Button_Click
{
foreach(DataGridVewRow dgvr in dgvProductCorrections.Rows)
{
Decimal fCorrection;
//Check if value exists and it can be used. Add own other checks
if(dgvr.Cells(this. dgvProductCorrection_Correction.Name).Value != null && Decimal.TryParse(dgvr.Cells(this.dgvProductCorrection_Correction.Name).Value.ToString(), fCorrection) = True)
{
//Here you can put a update code, or save a correction in list and then update all by one update call
}
}
}
請粘貼您的用戶界面的代碼或屏幕截圖。沒有得到你所擁有的和你想要達到的。 – Freelancer 2013-03-12 12:44:13
你想只在網格中做這些事情嗎? – Freelancer 2013-03-12 12:45:50
請快速回復,因爲當您提出問題時,我們會爲此付出一些努力。所以PLZ有一些尊重。 – Freelancer 2013-03-12 12:49:37