2010-07-19 71 views
0

我想遍歷gridview中的所有行並從RepositoryLookupEdit中檢索數據。從GridView獲取RepositoryLookupEdit

基本上我想這樣做,但我不知道如何讓RepositoryLookupEdit:

For i as Int32 = 0 to myGridView.RowCount -1 
    Dim row As DataRowView = CType(myGridView.GetRow(i), DataRowView) 
    //'This next line does not work 
    Dim lue As LookUpEdit = row.Item("myColumn").myRepLookupEdit 
    Dim drv As DataRowView = CType(editor.Properties.GetDataSourceRowByKeyValue(lue.EditValue), DataRowView) 
    Dim myData As Int32 = CType(drv("myData"), Int32) 
Next 

回答

1

我認爲你應該使用下面的代碼:

For i as Int32 = 0 to myGridView.RowCount -1 

    Dim cellValue As object = myGridView.GetRowCellValue(i, "myColumn") 
    dim dView as DataView = new DataView(repositoryItemGridLookupEdit.DataSource) ' you should pass a DataTable instance here 

    dim rowIndex as integer = dView.Find(cellValue) 
    dim otherCellValue as object = dview(rowIndex)("myData") 
Next 

不這個工作給你?

+0

這很好,我有一個BindingSource作爲我的數據源,所以我有ctype數據源到我的數據集,然後引用我的數據表 – 2010-07-20 15:22:09