|
I have a Public Sub that returns values from an Access database and populates a combo box. I have another sub that is called when the selected value of the combo box changes. I want the second sub to be able to access the data table that was retrieved earlier and check for a flag that may or may not be set. Can a data table be passed? Or is this not the proper method to do this?
Thanks,
Dan
|
|
|
|
|
Yes, you can pass a DataTable, but unless you're processing the data in the entire table, you should only be passing the row in question.
|
|
|
|
|
How about this, what I have done is passed to the other the .text value of my combo box. So my function call looks like this:
<br />
TwentyFourHourReport(cboDiseaseName.Text)<br />
And inside of my sub I have created a new SQL statement that looks for the particular row in the data base that corresponds with the above .text value and return two columns, one for the DiseaseName and the other for TwentyFourHourFlag.
Thanks again Dave
|
|
|
|
|
A combo has both value and display members. Usually, if you're going to pick something from a combo that's been populated by records from a table, you pass the value (normally the record ID) to a function that will return that record from the database.
|
|
|
|
|
Dave,
While in a meeting I had some time to think about this. What I am trying to do is this, I have a Sub that populates the combo box on a form -
<br />
Public Sub DiseaseList(ByVal connectionString As String)<br />
'Disease List<br />
Dim strSQLDiseaseList As String = "Select DiseaseName, DiseaseCode, SurveillanceFormFlag, TwentyFourHRReportFlag, CausativeOrganismFlag, SerotypeFlag, SiteOfInfectionFlag From Disease"<br />
Dim daDisease As New OleDbDataAdapter(strSQLDiseaseList, connectionString)<br />
Dim dtDisease As New DataTable("Disease")<br />
<br />
Try<br />
daDisease.Fill(dtDisease)<br />
Catch ex As Exception<br />
MessageBox.Show(ex.Message)<br />
End Try<br />
<br />
'daDisease.Fill(dtDisease)<br />
<br />
With cboDiseaseName<br />
.DropDownStyle = ComboBoxStyle.DropDownList<br />
.DataSource = dtDisease<br />
.DisplayMember = "DiseaseName"<br />
.ValueMember = "DiseaseCode"<br />
.SelectedIndex = cboDiseaseName.FindStringExact("")<br />
End With<br />
'End Disease List<br />
End Sub<br />
Then I have an event for SelectedValueChanged -
<br />
Private Sub cboDiseaseName_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboDiseaseName.SelectedValueChanged<br />
Dim strDiseaseName As String<br />
<br />
TwentyFourHourReport(cboDiseaseName.Text, StrConnectionToDatabase())<br />
End Sub<br />
I will eventually have 4 function calls in the above Sub to test for flags set in the database.
In the function (which I am still in the middle of writing) will test to see if the flag is set, if it is then it will display a label informing the user of a 24 hour reporting criteria.
Having read your most recent reply I was thinking that I could actually query the DataTable that I filled with the first Sub to find out if the TwentyFourHRReportFlag is set. This way I am not making another call to the database when I should have the data in a DataTable already.
Also, if I place a message box in the cboDiseaseName_SelectedValueChanged Sub I will get that message box to pop up about 4 times before the form actually loads. I think it is due to database calls for the other combo boxes but I am not sure. Is there a better way than SelectedValueChanged to be the event to check for changed criteria?
Thanks,
Dan
|
|
|
|
|
HurricaneDan wrote: This way I am not making another call to the database when I should have the data in a DataTable already
Great! Why make another round trip if you already have the data. All you have to do if Filter the datatable by the DiseaseCode and you should get a single row returned.
HurricaneDan wrote: Also, if I place a message box in the cboDiseaseName_SelectedValueChanged Sub I will get that message box to pop up about 4 times before the form actually loads.
SelectedValue will get fired once after the combo is bound to the data. If you have a MsgBox in each combobox's SelectedValueChanged event, this is why you're getting 4 Message Boxs.
No, there is no "better method" of doing this.
|
|
|
|
|
Right now I only have the MsgBox in the one Sub but it calls it multiple times. I have something I will try when I get into work tomorrow and see if this works.
I have also been reading some various posts on CP and I have noticed that you are one of the most active posters. I have also seen some of your posts to people in answer to some crazy questions. Your patience is pretty good. Did you ever find out what the hell >.< means? It looks like a set of mouse whiskers.
Thanks again,
Dan
|
|
|
|
|
HurricaneDan wrote: have also been reading some various posts on CP and I have noticed that you are one of the most active posters. I have also seen some of your posts to people in answer to some crazy questions. Your patience is pretty good.
After doing this for 4 years, you can really tell the difference between the newbies who want their hjomework done for them and the people who actually have a question!
HurricaneDan wrote: Did you ever find out what the hell >.< means?
Nope.
|
|
|
|
|
Hi all,
How to get serial number of monitor?
I think that's difficult, because in our system environment variables, serial number of monitor is not record.
If you have any ideas, please tell me.
Thank you
|
|
|
|
|
The only reliable way to get the serial number of the monitor is to turn it around and look at the tag with your Mark 1 Eye Ball.
It can be done in code, but not reliably. There is nothing in the EDID spec that says the manufacturer of a monitor has to supply the serial number in the data the monitor sends to the machine.
Here[^] is the code sample to do it. Be sure to read the code comments for why this will not work 100% of the time.
|
|
|
|
|
Hi All,
I'm developing an on-screen keyboard using VB.NET and need some advice. Currently, I'm using a few User32 API calls to GetActiveWindow() and SetActiveWindow(). Right now, I've got the active window handle number and using it as follows: SetActiveWindow(8975651603260375040), which seems to work... kind of. The desired window receives the focus but as the user types, the window receiving the focus flickers as my keyboard application sets focus to it just before it sends the keystroke to that window.
The keystroke is indeed sent to that window, but as suggested by another Code Project member, I would like for my keyboard to always keep the focus and then use SendMessage or SendInput to send the key strokes to the desired window that the user had previous selected before they began typing.
I've googled SendMessage, SendInput, etc, and not found many examples that illustrate window focus and how SendMessage actually works in the context of a virtual keyboard.
Any help would be much appreciated!!
Thank! -Patrick
|
|
|
|
|
i want to make a cell of a datagrid as a button...
i am using .NewRow predefined function to add a new row.. i am not using any data adapter neither data set... i am adding new row straight to the datagrid...
what should i need to do...
please help me...
i am using vb.net 2002.
if ever, much better if you can give me sample codes. thanks!
|
|
|
|
|
Depending on where the new row is added, you can use a RowDoubleClick or Click event to process the data in that field. For example, if the row is added to the end of the data grid, you can use a collection of the rows and access the last element of the collection array directly.
Then, you could systematically go through the cells you want to extract the data out of by passing the column name to one of the functions provided by the data grid class (something like SelectedIndex() or Index() and then you pass the name of the column).
Hope this helps.
|
|
|
|
|
i already know about that... but i really need to put a button in a cell. but thanx anyway...
|
|
|
|
|
Oh, sorry. Didn't understand what you meant. Good luck!
|
|
|
|
|
I'm creating a control and don't want it to be resizable. Most people say to hide it from the designer and throw an error when it's called, but I can't do that because the Size property isn't overrideable! Right now I set the size back the the default height and width in the resize event, but this may be confusing to the user as it looks resizable.
Thanks,
Nick
|
|
|
|
|
|
Thanks! I ran the example code there through a translator and found out you use the shadows keyword.
|
|
|
|
|
great
|
|
|
|
|
|
|
You can easily fix a controls size by overriding SetBoundsCore. It looks like this.
Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As System.Windows.Forms.BoundsSpecified)
Const fixedWidth As Integer = 50
Const fixedHeight As Integer = 50
MyBase.SetBoundsCore(x, y, fixedWidth, fixedHeight, specified)
End Sub
I know changing the size back in the resize event will also work, but doing it that way actually allows the control's size to be changed and then it quickly changes it back. Overriding SetBoundsCore will prevent the change from ever occurring.
|
|
|
|
|
hi All
i have a textbox that sometimes Should be Null and my table field is Nullable. When the textbox has no Entry i want to put Null in my Field.
thanks
Vuyiswa
|
|
|
|
|
Then check the Text property on the text box. If it is an empty string String.Empty then put null (DBNull.Value ) in your column, otherwise put the value of the Text property in.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
Ready to Give up - Your help will be much appreciated.
My website
|
|
|
|
|
Thanks you For your reply.
i understand the Logic, if the textbox is Empty string the set it to Null, but code wise i dont understand. please post me a skeleton code to learn from it.
Thanks Colin
Vuyiswa
|
|
|
|