使用ComboBox在绑定源筛选器中选择DataColumn [英] Use a ComboBox to select a DataColumn in a Binding Source Filter

查看:70
本文介绍了使用ComboBox在绑定源筛选器中选择DataColumn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



首先,我想感谢您在本网站上找到的精彩文章!



好​​吧,我遇到绑定源的过滤方法有问题。

我的想法是使用组合框来选择过滤器所在的列方法是

去寻找插入文本框的文字。



这是我的猜测:

Hi everyone,

First of all I would like to thank you for the great articles we can find on this web site!

Well, I''m having a problem with the filter method of the binding source.
My idea is to use a combo box to select the column where the filter method is
going to look for the text inserted in a text box.

Here is my guess:

Private Sub TextBox12_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox12.TextChanged

        Me.InventarioCompletoBindingSource.Filter = "(ComboBox1.Text) LIKE '" & TextBox12.Text & "%'"

End Sub



这给了我这个错误:


This gives me this error:

The column Combobox1 can't be found





有什么想法吗?



谢谢你提前



Any ideas?

Thank you in advance

推荐答案

Private Sub TextBox12_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox12.TextChanged

        Me.InventarioCompletoBindingSource.Filter = "(ComboBox1.SelectedItem.ToString()) LIKE '" & TextBox12.Text & "%'"

End Sub


它有效!谢谢Krunal



我已经将Combobox1.selectedvalue.tostring和if then语句结合起来处理我的combobox1集合中的每个项目以及这是什么都没有。



这是我做的:



It works! Thank you Krunal

I''ve combined the "Combobox1.selectedvalue.tostring" with the "if then" statement to handle every item in my combobox1 collection and also the posibility of it being nothing.

Here is what I did:

Quote:

Private Sub TextBox12_TextChanged(ByVal sender As System.Object,ByVal e As System.EventArgs)处理TextBox12.TextChanged



如果ComboBox1.SelectedItem = Nothing那么

Me.InventarioCompletoBindingSource.Filter =COD1 LIKE''& TextBox12.Text& %''或EQUIPO LIKE''& TextBox12.Text& %''或MARCA LIKE''& TextBox12.Text& %''或MODELO LIKE''& TextBox12.Text& %''或SER SER LIKE''& TextBox12.Text& %''或UBICACION LIKE''& TextBox12.Text& %''或ZONA LIKE''& TextBox12.Text& %''或LUGAR LIKE''& TextBox12.Text& %''或ESTADO LIKE''& TextBox12.Text& %''

ElseIf ComboBox1.SelectedItem.ToString =Equipo然后

Me.InventarioCompletoBindingSource.Filter =EQUIPO LIKE''& TextBox12.Text& %''

ElseIf ComboBox1.SelectedItem.ToString =Marca然后

Me.InventarioCompletoBindingSource.Filter =MARCA LIKE''& TextBox12.Text& %''

ElseIf ComboBox1.SelectedItem.ToString =Modelo然后

Me.InventarioCompletoBindingSource.Filter =MODELO LIKE''& TextBox12.Text& %''

ElseIf ComboBox1.SelectedItem.ToString =Serie然后

Me.InventarioCompletoBindingSource.Filter =SERIE LIKE''& TextBox12.Text& %''

ElseIf ComboBox1.SelectedItem.ToString =Ubicacion然后

Me.InventarioCompletoBindingSource.Filter =UBICACION LIKE''& TextBox12.Text& %''

ElseIf ComboBox1.SelectedItem.ToString =Zona然后

Me.InventarioCompletoBindingSource.Filter =ZONA LIKE''& TextBox12.Text& %''

ElseIf ComboBox1.SelectedItem.ToString =Lugar然后

Me.InventarioCompletoBindingSource.Filter =LUGAR LIKE''& TextBox12.Text& %''

ElseIf ComboBox1.SelectedItem.ToString =Estado然后

Me.InventarioCompletoBindingSource.Filter =ESTADO LIKE''& TextBox12.Text& %''

ElseIf ComboBox1.SelectedItem.ToString =Todos然后

Me.InventarioCompletoBindingSource.Filter =COD1 LIKE''& TextBox12.Text& %''或EQUIPO LIKE''& TextBox12.Text& %''或MARCA LIKE''& TextBox12.Text& %''或MODELO LIKE''& TextBox12.Text& %''或SER SER LIKE''& TextBox12.Text& %''或UBICACION LIKE''& TextBox12.Text& %''或ZONA LIKE''& TextBox12.Text& %''或LUGAR LIKE''& TextBox12.Text& %''或ESTADO LIKE''& TextBox12.Text& %''

结束如果



End Sub

Private Sub TextBox12_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox12.TextChanged

If ComboBox1.SelectedItem = Nothing Then
Me.InventarioCompletoBindingSource.Filter = "COD1 LIKE ''" & TextBox12.Text & "%'' OR EQUIPO LIKE ''" & TextBox12.Text & "%'' OR MARCA LIKE ''" & TextBox12.Text & "%'' OR MODELO LIKE ''" & TextBox12.Text & "%'' OR SERIE LIKE ''" & TextBox12.Text & "%'' OR UBICACION LIKE ''" & TextBox12.Text & "%'' OR ZONA LIKE ''" & TextBox12.Text & "%'' OR LUGAR LIKE ''" & TextBox12.Text & "%''OR ESTADO LIKE ''" & TextBox12.Text & "%''"
ElseIf ComboBox1.SelectedItem.ToString = "Equipo" Then
Me.InventarioCompletoBindingSource.Filter = "EQUIPO LIKE ''" & TextBox12.Text & "%''"
ElseIf ComboBox1.SelectedItem.ToString = "Marca" Then
Me.InventarioCompletoBindingSource.Filter = "MARCA LIKE ''" & TextBox12.Text & "%''"
ElseIf ComboBox1.SelectedItem.ToString = "Modelo" Then
Me.InventarioCompletoBindingSource.Filter = "MODELO LIKE ''" & TextBox12.Text & "%''"
ElseIf ComboBox1.SelectedItem.ToString = "Serie" Then
Me.InventarioCompletoBindingSource.Filter = "SERIE LIKE ''" & TextBox12.Text & "%''"
ElseIf ComboBox1.SelectedItem.ToString = "Ubicacion" Then
Me.InventarioCompletoBindingSource.Filter = "UBICACION LIKE ''" & TextBox12.Text & "%''"
ElseIf ComboBox1.SelectedItem.ToString = "Zona" Then
Me.InventarioCompletoBindingSource.Filter = "ZONA LIKE ''" & TextBox12.Text & "%''"
ElseIf ComboBox1.SelectedItem.ToString = "Lugar" Then
Me.InventarioCompletoBindingSource.Filter = "LUGAR LIKE ''" & TextBox12.Text & "%''"
ElseIf ComboBox1.SelectedItem.ToString = "Estado" Then
Me.InventarioCompletoBindingSource.Filter = "ESTADO LIKE ''" & TextBox12.Text & "%''"
ElseIf ComboBox1.SelectedItem.ToString = "Todos" Then
Me.InventarioCompletoBindingSource.Filter = "COD1 LIKE ''" & TextBox12.Text & "%'' OR EQUIPO LIKE ''" & TextBox12.Text & "%'' OR MARCA LIKE ''" & TextBox12.Text & "%'' OR MODELO LIKE ''" & TextBox12.Text & "%'' OR SERIE LIKE ''" & TextBox12.Text & "%'' OR UBICACION LIKE ''" & TextBox12.Text & "%'' OR ZONA LIKE ''" & TextBox12.Text & "%'' OR LUGAR LIKE ''" & TextBox12.Text & "%''OR ESTADO LIKE ''" & TextBox12.Text & "%''"
End If

End Sub


这篇关于使用ComboBox在绑定源筛选器中选择DataColumn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆