Dynamic dropdown based on Radio selection - sql

Good morning all! Myself and a co-worker are tasked with a system-wide scripting solution but neither of us are .NET programmers so we need your help.
We have a GUI that displays a radio selection box (3 options) that are the three sites where our hospitals are. We need to dropdown located on the form to fill with only the locations based on the selected radio option.
my gui http://web6.twitpic.com/img/40330741-85d91a5637f2445b322e62df17cf3351.4aef01c5-full.jpg
Here is the code behind we have so far (sorry, VB)
Public Class frmCEHLI
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CELocDataSet.dbo_Locations' table. You can move, or remove it, as needed.
Me.Dbo_LocationsTableAdapter.Fill(Me.CELocDataSet.dbo_Locations)
End Sub
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
MsgBox("Submit button has been pressed")
End Sub
End Class
For the record the Location dropdown is currently databound but its a static SELECT statement which brings us all the locations but we'd prefer it to be cleaner if it only returned the locations based on Site. We are using Visual Basic 2008 Express Edition for development. Any help/code is appreciated, thanks!

Sorry not to respond back sooner, busy, and wanted to dig up a sample that did just what you were needing.
Create two comboboxes on your form. You can bind either fixed values, or from a table on the first combo. Then, from the property/events sheet, first set the "AutoPostBack" to TRUE, then on the events, click for the "SelectedIndexChanged" event to bring up some code.
The "Sender" object parameter will be the combobox itself, so you'll be able to analyse the property settings via debugging to find what key/value was chosen.
Then, run whatever query from your data querying control, business object, or whatever that gets your results, such as to a DataSet or DataTable.
Finally, set the datasource of your second combo to the above result query, set dataTextField and DataValueField and issue DataBind() to the combo.
That should get exactly what you need.
Then, when someone makes a selection from the second combo, you can have code within ITS "SelectedIndexChanged" event (also based on its AutoPostBack or actual submit button on the form).
Hope this helps.

I would create two combobox controls... One for the "where", then, on the InteractiveChange event by the user to post-back to the page using that answer for the second combobox of locations based on the "where" value of the first combo.

Related

How to retain contents of datagrid view when applying multiple filters

I am trying to provide my users a nice search capability. I want to do so using textboxes to filter a datagridview. I have a dgv containing all animals in the database. For simplicity sake let’s say the first two columns are animalName and animal (dog or cat). I have two textboxes used for filtering, one for each of those two columns. Let's say I want to find all dogs named Buddy. In my first text box I type 'Buddy' and, because of the filter code behind the textbox change event the dgv now contains only the Buddys. When I go to textboxAnimal and type 'd' for dog the dgv changes to show all the dogs; not just the ones named Buddy. How can I make it such that the results of the first filter stay in place when I apply the second filter?
I assume I need to use the lostFocus (or gotFocus or leave) event of the first textbox but just don’t know what code to put behind it. I guess I could hard code a select statement that would then be used to repopulate the datagridview but this could get onerous as I’m going to have many textboxes; not just two.
Any help would be greatly appreciated.
Focus is irrelevant. You handle the TextChanged event of both TextBox controls and you build the filter from scratch every time, taking both fields into account, e.g.
Private Sub TextBoxes_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged,
TextBox2.TextChanged
Me.BindingSource1.Filter = String.Format("Column1 LIKE '%{0}%' AND Column2 LIKE '%{1}%'",
TextBox1.Text,
TextBox2.Text)
End Sub
One pitfall of filtering on TextChanged, regardless of how many fields you're filtering on, is that you will end up filtering needlessly several times when the user types several letters. For instance, if the user intends to type "bud" then there's no point to filtering after the "b" and the "bu" and it may actually degrade performance if the data set is large. For that reason, it's nice to use a Timer to delay filtering for a short period. That will defer filtering until the user stops typing in most cases. You can play with the Interval to get the performance you want. Probably about 500 ms should do it but it's up to you.
Private Sub TextBoxes_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged,
TextBox2.TextChanged
'Start or restart the timer because the user typed something.
Me.Timer1.Stop()
Me.Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'The timer has expired so the user has not typed anything for the prescribed amount of time.
Me.BindingSource1.Filter = String.Format("Column1 LIKE '%{0}%' AND Column2 LIKE '%{1}%'",
TextBox1.Text,
TextBox2.Text)
End Sub

Simple, but I'm stuck ....Updating a DataSet using code

I have a simple Windows form in VB: textbox bound thru an adapter and a bindingsource to my dataset.
I have a button that on Click I want it to update the database. The form loads and the first data row shows in the textbox, I change the text then click my button but no update happens.
Any ideas what I'm doing wrong, or how I should do this??
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.AToolsTableAdapter.Fill(Me.Qedsandb_TroyDataSet.aTools)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
AToolsTableAdapter.Update(Qedsandb_TroyDataSet.aTools)
End Sub
End Class
Assuming the click event runs(?), TableAdapters based on a query (a join) do not, by default, have the ability to update the database. The name of your binding source suggests that you are using a query.
MSDN: TableAdapter Overview
The update functionality of a TableAdapter is dependent on how much
information is available based on the main query provided in the
TableAdapter Wizard. For example, TableAdapters that are configured to
fetch values from multiple tables (JOINs), scalar values, views, or
the results of aggregate functions are not initially created with the
ability to send updates back to the underlying database. However, you
can configure the INSERT, UPDATE and DELETE commands manually in the
Properties window.
You don't appear to be moving the data back from the form to the dataset. Try calling EndEdit on your bindingsource.

How can you make new form as a copy (in runtime) of an already shown form?

I am trying to make a form that functions as "READ/OPEN MAIL".. so what I want is to have multiple forms (which is a copy, with both the designer and form functions e.g. buttons and codes) when I open multiple mails.
I know how to create a new window but I do not know how to copy the designer codes and functions from anoher form and apply it to the newly created form. I have searched google but it only directs me to different questions. Thanks in advance!
All you have to do is create a variable of the type of your class, then show it using the Show method.
i.e.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim myform As Form1 = New Form1
myform.Show()
End Sub

How to update value in combo box using combo box text?

I have a very simple question that i can't seem to find the answer, i have looked up and down in google, msdn with no luck...
it's really simple yet i can't seem to wrap my mind around it.
here goes:
If i'm using simple Drop down style combo box(the one that looks like a listbox with textbox attached on top of the cbobx control) when i want to update one of the value in it, once i start typing in the textbox the selection inside the combo box is gone. Thus i can't update the value inside the combo box.
i know i can use a regular text box to do this, but i'd really like to make this work or i would really loose sleep over this.
Thanks in advance for all your help.
Ray
It doesnt seem very intuative editing the selection in a combobox, but the following should do the trick:
Private cbindex As Integer
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
cbindex = ComboBox1.SelectedIndex
End Sub
Private Sub ComboBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.LostFocus
ComboBox1.Items(cbindex) = ComboBox1.Text
End Sub

VB 2008 Displaying data in ListBox then Transfer the data to another ListBox

In VB 2008 I created 2 list box. The first list box is to load all the data in my database in a specific row, the other list box is when I double click on the data/item on the first list box the specific data/item need to be transfer to the second list box.
I manage to transfer the data, but the output it gave was wrong. Instead of the actual name of the given data/item the output it gave was System.Data.DataRowView. I tried using .ToString() but nothing happens. I used the drag and drop method for the data adapter connection and the database I'm using is MySQL. I use the "Use data bound items" on list box 1.
You should do it like this,
Private Sub ListBox1_DoubleClick(sender As Object, e As EventArgs) _
Handles ListBox1.DoubleClick
' checks if the item is empty
If ListBox1.SelectedItem.ToString.Length <> 0 Then
' adds on listbox 2
ListBox2.Items.Add(ListBox1.Text)
End If
End Sub
See this,
with simple code you can use this
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
ListBox2.Items.Add(ListBox1.SelectedItem)
End Sub