以下代码有效(行由select表达式过滤),但是datarepeater中的所有控件都是空的。设置为.DefaultView时,所有记录都返回,所有控件都有其值。
Private Sub CheckBox_FilterApplied_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox_FilterApplied.CheckedChanged
If CheckBox_FilterApplied.Checked Then
' RichTextBox_Notes.DataBindings.Add("Text", dsTransactions.Tables("TransactionHeader"), "Note")
DataRepeater_Transactions.DataSource = dsTransactions.Tables("TransactionHeader").Select("Applied = 0")
DataRepeater_Transactions.Refresh()
Else
DataRepeater_Transactions.DataSource = dsTransactions.Tables("TransactionHeader").DefaultView
End If
End Sub
不知道遗失了什么。刷新没有帮助。
答案 0 :(得分:1)
我认为问题是因为DataRepeater的Textbox和Datasource的DataSource。
我稍微修改了代码,请试一试。适合我。
Dim dt As New DataTable
dt.Columns.Add("Col1")
dt.Columns.Add("Col2")
dt.Columns.Add("Col3")
For index = 1 To 10
Dim dr As DataRow = dt.NewRow()
dr("Col1") = index.ToString()
dr("Col2") = index.ToString()
dr("Col3") = index.ToString()
dt.Rows.Add(dr)
Next
Dim dv As DataView = New DataView(dt, "Col1 >= 8", "", DataViewRowState.CurrentRows)
TextBox1.DataBindings.Add(New Binding("Text", dv, "Col3"))
DataRepeater1.DataSource = dv
希望有所帮助:)
答案 1 :(得分:1)
DefaultView
属性的类型为DataView
,其IEnumerable
枚举DataRowView
数组,使您可以使用标准绑定语法。但是,Select
方法返回DataRow
个对象的数组,这些对象不能以相同的方式绑定。最简单的解决方案是确保将DataView
传递给DataSource
属性。
If CheckBox_FilterApplied.Checked Then
Dim dt As DataTable = dsTransactions.Tables("TransactionHeader")
Dim dv As DataView = New DataView(dt, "Applied = 0", "", DataViewRowState.CurrentRows)
DataRepeater_Transactions.DataSource = dv
Else
DataRepeater_Transactions.DataSource = dsTransactions.Tables("TransactionHeader")
End If
另请注意,它可以直接绑定到DataTable
,并且不需要显式使用DefaultView
属性,因为它将默认使用。