Hello!
Im very new to programing in VB. I have a database with info about some persons. I've managed to let the user select the name from the listbox and other info apeears on the form. Now I want to build in a search. I want to let the user to select gander, hair color, eyecolor etc. But if i use data bound items on gander I get gander info of every person (of course :P). So how to get in the gander combo box only 2 options (male/female) and get the result - info about all males/all females. I've tryed building querys, using DISTINCT command after SELECT but nothing seem to work.
I have another little problem. I update an image allways when the listbox value is changed - that works fine. But practicly the same sub, that checks if the combo box value is changed, doesent work ok. It refreshes my image the first time when I already select the third person. (when i select the second person the image doesent refresh and when i select the third person, the image refreshes but i het the image of the second person). What other action can i use except the combobox value changed
Thank you for your answers...

Using multiple data bound items
GazCoder
Thankyou!
I havent had the time to try filtering.
But the combobox is still a problem. If it helps my code looks something like this (its not fully optimized yet):
Private Sub PersonIDComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PersonIDComboBox.SelectedIndexChanged
My.Computer.FileSystem.CurrentDirectory = _path
Dim picpath As String
If ImageTextBox.Text = Nothing Then
picpath = "images\notdefined.jpg"
Else
picpath = "images\" & ImageTextBox.Text
End If
PictureBox1.Image = New Bitmap(picpath)
End Sub
MarkD08
Thankyou, now I undestand how this works, but I have some problems with it. Just for a test, I used the folowing sentence:
BindingSource.Filter = String.Format("Gender like '%{0}%'", "GenderComboBox.Text")
Possible genders are male and female. It doesent matter what I select male, female or notthing, I never get out any results(names).
If i delete the % signs I get the right result if I selecet a gender (that is expected), but if I don't select anything, I got a syntax error: Missing operand.
Any ideas how to solve this
anacomc
Super, thank you... that works great now.
Practicly the same procedure in the other form handles ListBox.SelectedIndexChanged, should I for any reason change that one too, into MyBindingSource.CurrentChanged or is it OK the way it is It works fine, but is it possible that it has some side effects
Nebelung
hi,
it will return all the persons that have a name like that who also 27 years old
for example if you have 2 "ibraham" in your database one 27 YO and the other one 29 it will just return the first one and will ignore the other one, you might use or to return all
hope this helps
Hemant1408
hi,
you are welcome
i saw this problem just with combobox(i don't remember exactly "i got the same result by using combobox.dropdownclosed event without using the datasrouce" i guess its issue related to events like the selectedindexchanged happen b4 the change will be submited, but when u use dropdownclose you will be sure that the changes was submited),
i don't remember listbox gave me that error b4
best regards
richie m
So if i undestand this right. If I search for "name like '%textbox.text%' AND age='27'" and leave the textbox empty, it will return me all the persons from the database that are 27 years old
ram krishna tripathi
hi,
you can use and in the filter and you can use wildcard search
like for example
BindingSource.Filter = string.format("Name like '%{0}%' and Age <{1} and Age >{2} and EyeColor='{3}' " , textbox1.text, int.parse(textbox2.text, int.parse(textbox3.text, EyeColorComboBox.selectedItem")
like that if you search about the name abc it will return all the records that contains a name have this part " abc " for example, and will give you age between two values , and color
not the text columns wrapped in single quotes' '
hope this helps
Mark-Allen
hi,
regarding filtering your data(search) you can take a look to this thread
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=339281&SiteID=1
about the combobox you can use selectedindexchanged event
Private Sub listbox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listbox1.SelectedIndexChanged
'Todo: add your code here
endsub
hope that helps
Northwester
Ok, I managed to get to the filtering data part...
In my case, I'd like to use 5 filters or less. User can choose some options from 5 comboboxes that u can fitler by. If user chooses to use all 5 of them it is ok, I just make a filter sentence with all filter options in it, connected with AND operators. But if he chooses to use less i'd have to do an if or case sentence for every option possible.
It would be cool to get it to work something like this:
BindingSource.Filter = "Name='" & NameComboBox.text & "'"
BindingSource.Filter = "EyeColor='EyeColorComboBox.text'"
than all I'd had to do would be an if sentence before every filtering, where i'd check if any option was selected... something like that:
BindingSource.Filter = "Name='" & NameComboBox.text & "'"
if DaysUsed.text <> nothing then
BindingSource.Filter = "EyeColor='EyeComboBox.text'"
endif
and so on...
So is there a way to do 5 or less filterings easyly
Thank you and sorry for the mistakes in my post, I hope you can resolve trough the examples what I want to do :)
Gokul_
hi,
the problem isn't in your combobox indexchanged event handler at all , the problem in your code because no relationship between your combobox and textbox
if both are bound to the same bindingsource, use the bindingsource to retrieve the value not the combobox
'this will not work the messageboxs will show you the previous selection 'for example if you display record 2 and you changed the selection to record 5 'the messageboxs will show record 2 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim value As String = Me.MyBindingSource.Current("GroupID_Grp")
MessageBox.Show(value)
MessageBox.Show(Me.TextBox1.Text)
End Sub 'this is the correct use Private Sub _01_GroupsBindingSource_CurrentChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBindingSource.CurrentChanged
Dim value As String = Me.MyBindingSource.Current("GroupID_Grp")
MessageBox.Show(value)
MessageBox.Show(Me.TextBox1.Text)
End Sub
"GroupID_Grp" this is my column name in mytable, you can use the column name as string or the column index
hope this helps