2012-02-15 30 views
0

我很想知道爲什麼這個代碼把值5在列的單元格datagridview的形式負載

For Each row As DataGridViewRow In Me.datagridADRORD.Rows 
     row.Cells("Historical Diff").Value = 5 
    Next 

但這代碼不起作用,即單元格爲空。有值的公式的單元格所以應該有一個價值擺在計算列

For Each row As DataGridViewRow In Me.datagridADRORD.Rows 
     row.Cells("Historical Diff").Value = row.Cells("ADR Price").Value - row.Cells("ORD Price").Value 
    Next 

回答

0

請儘量細胞指標,而不是小區名稱。

// 1是細胞指數

row.Cells(1).Value = 5 
+0

硬編碼值正常工作,即使列名,配方沒有,這就是問題 – dinotom 2012-02-15 01:28:25

+0

好難過。對於公式,轉換十進制或整數。 Integer.Parse( 「23」);或Decimal.Parse(「23.20」) – 2012-02-15 01:38:30