1)DataLayout可以自动根据绑定的数据生成需要的label和Text. 不过它需要设计时支持.
我研究了下如何动态绑定, 上代码:
x = New InterviewersService
Dim t As Interviewers = x.GetByIntid("100002")
Dim y As New BindingList(Of Interviewers)
y.Add(t)
Me.DataLayoutControl1.DataSource = y
Me.DataLayoutControl1.RetrieveFields()
2)那么在修改后如何写回去呢?继续上:
Dim a As CurrencyManager = CType(Me.DataLayoutControl1.BindingContext(Me.DataLayoutControl1.DataSource, Me.DataLayoutControl1.DataMember), CurrencyManager)
Dim b As Interviewers= CType(a.Current, Interviewers)
x.Save(b)
3) 如何修改自动生成的Datalayout呢?
'设置生成的label的文本
Me.DataLayoutControl1.Items(2).Text = "访问员编号"
For Each baseItem As BaseLayoutItem In DataLayoutControl1.Items
Dim item As LayoutControlItem = TryCast(baseItem, LayoutControlItem)
If Not item Is Nothing Then
If item.Control.DataBindings(0).BindingMemberInfo.BindingField = "EntityId" Or item.Control.DataBindings(0).BindingMemberInfo.BindingField = "Tag" Or item.Control.DataBindings(0).BindingMemberInfo.BindingField = "Error" Then
'Hide this item
DataLayoutControl1.AddToHiddenItems(item)
End If
End If
Next baseItem
太纠结了, 省的时间估计还没有用的多...算了还是手写拖控件吧, 至少更灵活