当我选择产品时,如何将值设置为gridview列price
?
所以我不需要手动输入。
Dim repo_lookupedit_gv2 As New Repository.RepositoryItemLookUpEdit
Public Sub load_product()
Dim perintah As New SqlCommand
Dim dt As New DataTable
Try
Using MyAdapter As New SqlDataAdapter
knk.MyConnection.Open()
dt.Clear()
With perintah
.Connection = knk.MyConnection
.CommandText = "select * from product"
MyAdapter.SelectCommand = perintah
MyAdapter.Fill(dt)
End With
End Using
repo_lookupedit_gv2.DataSource = dt
repo_lookupedit_gv2.ValueMember = dt.Columns("code").ToString
repo_lookupedit_gv2.DisplayMember = dt.Columns("product").ToString
repo_lookupedit_gv2.PopupWidth = 450
gridview2.columns("product").columnedit = repo_lookupedit_gv2
AddHandler repo_lookupedit_gv2.EditValueChanged, AddressOf repo_lookupedit_gv2_changed
Catch ex As Exception
MsgBox("Failed to load data product !")
Finally
knk.MyConnection.Close()
End Try
End Sub
Private Sub GridView2_InitNewRow(sender As Object, e As InitNewRowEventArgs) Handles GridView2.InitNewRow
Dim row As DataRow = GridView2.GetDataRow(e.RowHandle)
row("qty") = 1
row("price") = repo_lookupedit_gv2.Columns("price").ToString() \\\'it give me error
End Sub
我已经尝试了
Private Sub repo_lookupedit_gv2_changed(sender As Object, e As EventArgs)
MsgBox(repo_lookupedit_gv2.Columns("price").ToString())
End Sub
哪不给我任何东西
答案 0 :(得分:1)
Private Sub repositoryItemGridLookUpEdit1_EditValueChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim editor As GridLookUpEdit = TryCast(sender, GridLookUpEdit)
Dim index As Integer = editor.Properties.GetIndexByKeyValue(editor.EditValue)
If index < 0 Then
Return
End If
Dim value As Object = (TryCast(editor.Properties.View.GetRow(index), DataRowView)).Row("Name")
gridView2.SetFocusedRowCellValue("Name", value)
End Sub
请参阅上面的示例,您可以获取编辑器Row或Class对象,具体取决于您使用repositoryitem控件绑定的数据源类型。
在您的情况下,您将其与数据表绑定,然后您将获得DataRowView
,如图所示。之后,您可以使用方法gridView2.SetFocusedRowCellValue("Name", value)