|
-
Nov 11th, 2014, 07:33 PM
#41
Hyperactive Member
Re: refresh combobox values after updating its datatable and adapter
 Originally Posted by jmcilhinney
It's your application. You tell me. Here's how it works. You ask yourself exactly what happens in the application to prompt the data refresh. You then determine what event is raised or the like when that happens and that tells you where to put the code. I would guess that it's when the second form, i.e. the form that modifies and saves the data, closes but that is based on very limited information. It's your application; you know how you want it to work; you decide.
To me, selecting the combobox is the only logical answer. You click it and it should present the desired data. It's not doing that. So quite frankly if index changed isn't the place to query that database for the latest data... I don't know what is. If I did...the logic dictates I wouldn't need to be here asking.....
If you have a realistic solution, I'm listening. So far other than examining the structure of the binding sources and declaring that I have two different datasets with the suggestion to requery the database... I don't see where you're actually helping me resolve this. Understand something here. I know what I want the combobox to do and why I want it to do it. What I don't know is HOW TO MAKE IT HAPPEN..
-
Nov 11th, 2014, 08:05 PM
#42
Re: refresh combobox values after updating its datatable and adapter
 Originally Posted by larrycav
To me, selecting the combobox is the only logical answer. You click it and it should present the desired data. It's not doing that. So quite frankly if index changed isn't the place to query that database for the latest data... I don't know what is. If I did...the logic dictates I wouldn't need to be here asking.....
If you have a realistic solution, I'm listening. So far other than examining the structure of the binding sources and declaring that I have two different datasets with the suggestion to requery the database... I don't see where you're actually helping me resolve this. Understand something here. I know what I want the combobox to do and why I want it to do it. What I don't know is HOW TO MAKE IT HAPPEN..
You seem determined to assume you're right even though you know that what you're doing doesn't work. Consider this. You open that form and the ComboBox gets populated with 10 items from the database. You press the Tab key until that ComboBox receives focus. You now press the Down arrow key until the last item in the list is selected. That means that the SelectedIndexChanged event of the ComboBox will be raised 10 times. Are you saying that it makes sense to requery the database 10 times during that process?
I certainly hope not. It makes no sense to requery the database at all during that process because you know for a fact that the data in the database is still exactly the same as it was when you started. It only makes sense to requery the database when the data has, or at least may have, changed. What happens in your application when the data changes? I don't know because I'm not there and I've never seen your app and you've never described it in detail. You're sitting there in front of it and wrote it in the first place. If you don't know then who would?
Engage your brain. Like so many people, you seem to think that the only thing that qualifies as help is someone else doing your thinking for you. I won't be doing that.
-
Nov 12th, 2014, 11:04 PM
#43
Hyperactive Member
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
I fixed the problem. 
I was working on the wrong form for a solution. I needed to add code to the form with the datagridview rather than the from that actually contains the combobox.
Code:
Private Sub BtnUpdateOrificeData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdateOrificeData.Click
Me.OrificedataTableAdapter.Update(ProFlow1DataSet.orificedata)
Me.OrificedataTableAdapter.Fill(Me.ProFlow1DataSet.orificedata)
Me.OrificedataTableAdapter.Fill(frmMain.ProFlow1DataSet.orificedata)
MsgBox("Orifice Data Has Been Saved")
End Sub
-
Nov 12th, 2014, 11:55 PM
#44
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
 Originally Posted by larrycav
I fixed the problem.
I was working on the wrong form for a solution. I needed to add code to the form with the datagridview rather than the from that actually contains the combobox.
Code:
Private Sub BtnUpdateOrificeData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdateOrificeData.Click
Me.OrificedataTableAdapter.Update(ProFlow1DataSet.orificedata)
Me.OrificedataTableAdapter.Fill(Me.ProFlow1DataSet.orificedata)
Me.OrificedataTableAdapter.Fill(frmMain.ProFlow1DataSet.orificedata)
MsgBox("Orifice Data Has Been Saved")
End Sub
You weren't working on the wrong form. You were working with the wrong event, as I said. You could still put the code in the other form and, in fact, you should, but you are now at least invoking the code on the correct event.
-
Nov 13th, 2014, 04:13 PM
#45
Hyperactive Member
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
 Originally Posted by jmcilhinney
You weren't working on the wrong form. You were working with the wrong event, as I said. You could still put the code in the other form and, in fact, you should, but you are now at least invoking the code on the correct event.
What event is that?
-
Nov 13th, 2014, 04:54 PM
#46
Hyperactive Member
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
The root of the issue that I had stemmed from not knowing how VB handles database communication and structure. I know you're a Microsoft die hard from reading your posts and that's all well and fine. However this isn't my first go around with databases but it is my first go around with VB. Quite frankly the way it does some things causes confusion.
Once the other guy explained how the datasets are not global but instead are form by form entities by default, things began to click.
I have used Excel with ODBC drivers to pull data from Access and Progress databases in the past. I build a lot of reports for human resources, payroll, nursing, etc with excel by pulling data from a Progress backend database with their ODBC drivers.
In my Excel app of similar function I found it very straight forward to connect to, add and modify data using no GUI.. only code.
Now that I have a better understanding of how VB.net does things, I'll go another mile or two.....then stumble, fall down and ask more questions..
Thanks for the help.
Last edited by larrycav; Nov 13th, 2014 at 07:55 PM.
-
Nov 13th, 2014, 05:21 PM
#47
Hyperactive Member
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
 Originally Posted by larrycav
To me, selecting the combobox is the only logical answer. You click it and it should present the desired data.
The event for what you are describing is Enter (or possibly DropDown) not SelectedIndexChanged. The Enter event happens when a control gains focus such as when the user clicks the ComboBox. SelectedIndexChanged event occurs when the user selects one of the items in the ComboBox. But you want all of the items already in the ComboBox before the user makes a selection (otherwise they may complain that the new item isn't listed; they'd have to select an item to get all of the items refreshed and then make their actual selection a second time after the ComboBox has refreshed).
I have created this small program to show the difference. It has a Button (named btnTest1) and a ComboBox (named cboTest) and has a List(Of String) that the ComboBox's DataSource is connected to:
VB.Net Code:
Public Class Start
Public lstItems As New List(Of String)
Private Sub btnTest1_Click(sender As System.Object, e As System.EventArgs) Handles btnTest1.Click
With Me.lstItems
.Add("A")
.Add("B")
.Add("C")
End With
End Sub
Private Sub cboTest1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles cboTest1.SelectedIndexChanged
Me.cboTest1.DataSource = Nothing
Me.cboTest1.DataSource = Me.lstItems
End Sub
'Private Sub cboTest1_Enter(sender As Object, e As System.EventArgs) Handles cboTest1.Enter
' Me.cboTest1.DataSource = Nothing
' Me.cboTest1.DataSource = Me.lstItems
'End Sub
Private Sub Start_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.lstItems.Add("Hello")
Me.cboTest1.DataSource = Me.lstItems
End Sub
End Class
When the program runs, the ComboBox will initially just contain the word "Hello". When the button is clicked, the letters "A", "B", and "C" get added to the List. Then one of the ComboBox's events will trigger the List to be reset as its DataSource. Currently I have the SelectedIndexChanged handling the DataSource reset, but to see how the Enter event works, just comment out the SelectedIndexChanged handler and uncomment the Enter handler. Then do these steps to see the difference:
- Run the program and drop-down the ComboBox to see its initial items (eg the word "Hello")
- Click on the Button to add some more items to the List
- Drop-down the ComboBox again. If the Enter event handler is enabled, then you'll see all of the items listed (eg "Hello", "A", "B", and "C"); at this point you can quit. If the SelectedIndexChanged handler is enabled, then it will look like nothing happened and only the word "Hello" will be listed; you'll need to continue with the remaining steps to see the new items in the List for the ComboBox.
- While the ComboBox is in its drop-down state, click on the word "Hello". The ComboBox should close at this point (showing only the editable portion with the drop-down list hidden).
- Drop-down the ComboBox again to see that the DataSource was reset when you selected the word "Hello" in the previous step.
-
Nov 13th, 2014, 05:54 PM
#48
Hyperactive Member
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
 Originally Posted by Pyth007
The event for what you are describing is Enter (or possibly DropDown) not SelectedIndexChanged. The Enter event happens when a control gains focus such as when the user clicks the ComboBox. SelectedIndexChanged event occurs when the user selects one of the items in the ComboBox. But you want all of the items already in the ComboBox before the user makes a selection (otherwise they may complain that the new item isn't listed; they'd have to select an item to get all of the items refreshed and then make their actual selection a second time after the ComboBox has refreshed).
I have created this small program to show the difference. It has a Button (named btnTest1) and a ComboBox (named cboTest) and has a List(Of String) that the ComboBox's DataSource is connected to:
VB.Net Code:
Public Class Start
Public lstItems As New List(Of String)
Private Sub btnTest1_Click(sender As System.Object, e As System.EventArgs) Handles btnTest1.Click
With Me.lstItems
.Add("A")
.Add("B")
.Add("C")
End With
End Sub
Private Sub cboTest1_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles cboTest1.SelectedIndexChanged
Me.cboTest1.DataSource = Nothing
Me.cboTest1.DataSource = Me.lstItems
End Sub
'Private Sub cboTest1_Enter(sender As Object, e As System.EventArgs) Handles cboTest1.Enter
' Me.cboTest1.DataSource = Nothing
' Me.cboTest1.DataSource = Me.lstItems
'End Sub
Private Sub Start_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.lstItems.Add("Hello")
Me.cboTest1.DataSource = Me.lstItems
End Sub
End Class
When the program runs, the ComboBox will initially just contain the word "Hello". When the button is clicked, the letters "A", "B", and "C" get added to the List. Then one of the ComboBox's events will trigger the List to be reset as its DataSource. Currently I have the SelectedIndexChanged handling the DataSource reset, but to see how the Enter event works, just comment out the SelectedIndexChanged handler and uncomment the Enter handler. Then do these steps to see the difference:
- Run the program and drop-down the ComboBox to see its initial items (eg the word "Hello")
- Click on the Button to add some more items to the List
- Drop-down the ComboBox again. If the Enter event handler is enabled, then you'll see all of the items listed (eg "Hello", "A", "B", and "C"); at this point you can quit. If the SelectedIndexChanged handler is enabled, then it will look like nothing happened and only the word "Hello" will be listed; you'll need to continue with the remaining steps to see the new items in the List for the ComboBox.
- While the ComboBox is in its drop-down state, click on the word "Hello". The ComboBox should close at this point (showing only the editable portion with the drop-down list hidden).
- Drop-down the ComboBox again to see that the DataSource was reset when you selected the word "Hello" in the previous step.
Thank you for that...greatly appreciated 
Question... I need to alpha sort that bound combobox. I can't do it in properties because it's bound. Searching for code that does it but not finding it. Also, I expect I would place such code in designer.. is that correct?
-
Nov 13th, 2014, 06:04 PM
#49
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
 Originally Posted by larrycav
Thank you for that...greatly appreciated
Question... I need to alpha sort that bound combobox. I can't do it in properties because it's bound. Searching for code that does it but not finding it. Also, I expect I would place such code in designer.. is that correct?
Firstly, you might thank Pyth007 for trying, don't use their advice because it's wrong. Secondly, this new question has nothing to do with the topic of this thread so it belongs in a new thread dedicated to that topic.
-
Nov 13th, 2014, 08:01 PM
#50
Hyperactive Member
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
 Originally Posted by jmcilhinney
Firstly, you might thank Pyth007 for trying, don't use their advice because it's wrong. Secondly, this new question has nothing to do with the topic of this thread so it belongs in a new thread dedicated to that topic.
And you would call this what?????
Thank you for that...greatly appreciated
You have YET to answer a direct question I pose. You criticize the app structure yet you don't know how it's used. Then, to top it all off you post a double insult. One to me and one to Pyth007. Seriously...who elected you GOD anway?
Last edited by larrycav; Nov 13th, 2014 at 08:18 PM.
-
Nov 13th, 2014, 08:42 PM
#51
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
 Originally Posted by larrycav
And you would call this what?????
I wasn't saying that you had an obligation to thank someone that you hadn't met. I was saying that thanking someone for trying to help, which you did, is fine but you shouldn't use the information that they provided because it is not correct. I don't know whether you intended to or not but I was warning you not to because it would be detrimental to do so.
 Originally Posted by larrycav
You have YET to answer a direct question I pose.
Like so many people who post here and on other forums, you seem to believe that the only acceptable form of help is a turnkey solution that you can basically copy and paste without having to think for yourself. I have helped you but you are apparently unwilling to accept it because it requires you to put some thought and effort into following the direction provided to a solution. I can tell you absolutely that the SelectedIndexChanged event handler of the ComboBox is not the correct place to put code to do what you want to do. I can tell you absolutely that the Enter event handler of the ComboBox is not the correct place to put code to do what you want to do. What I can't do is tell what is the right event to use because you haven't provided enough information for me to do that. I specifically asked for it but you have apparently ignored my request.
 Originally Posted by jmcilhinney
It only makes sense to requery the database when the data has, or at least may have, changed. What happens in your application when the data changes? I don't know because I'm not there and I've never seen your app and you've never described it in detail. You're sitting there in front of it and wrote it in the first place. If you don't know then who would?
It's that information that will enlighten you - and me - as to what event you need to handle to be able to properly do what you want to do. You haven't provided that information so I can't tell you what event you should handle.
 Originally Posted by larrycav
You criticize the app structure yet you don't know how it's used.
You're absolutely right. I don't know how your app works so I can't tell you where you should put your code. If you had provided that information as I requested then I'd be able to provide the direct answer you want. You shouldn't need me to provide that answer though, because you should be able to think for yourself on what your app does when the data changes and what event, if any, is raised at that time. It might even be that it's not about handling an event at all but rather simply doing it after a call to ShowDialog returns. I don't know because you have chosen not to provide the information I need to make that judgement.
 Originally Posted by larrycav
Then, to top it all off you post a double insult. One to me and one to Pyth007. Seriously...who elected you GOD anway?
I'm not sure exactly what insults you're referring to. If you're implying that I accused you of not thanking someone when you should have then you have misinterpreted my words. If you're implying that my saying that the advice provided by Pyth007 is wrong is an insult then you're also wrong. To criticise what someone says is not inherently an insult. I don't know anything about Pyth007 so I make no judgements or statements about them as a person or even as a developer. I do know that you should not be handling the Enter event of your ComboBox to do what you want to do so I know that any advice to that effect is wrong. If I say black is white and you say I'm wrong, is that an insult? I certainly hope not.
-
Nov 14th, 2014, 02:26 PM
#52
Hyperactive Member
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
I didn't take your comment as an insult per se, but it did rub me wrong in that you just said I was wrong without any follow-up indicating why I was wrong. I tested out the code before I wrote that comment, so I know that it functions the way I thought it would. So in that sense, I wasn't wrong. And I've actually used that handler for a ComboBox in a program that was only one of several front-end applications in case some different station updated the database (actually looking back, I'd probably change it to the DropDown event to prevent an unnecessary hit to the database if a person focused on the ComboBox by tabbing through the form without actually using the ComboBox to make a selection).
If by saying I'm wrong you meant that it is not the ideal solution for the application under discussion, then I'd have to agree with you. Since it sounds like this program is the only thing that is changing the data, then it's better to update the ComboBox's contents when the change is made whether by explicitly programming it in or setting up proper data binding to both controls so that each reflects any changes the other has made.
My example was less as a solution to the problem (esp. since larrycav had mentioned how the problem was solved by moving the code to the update button's click event), but rather more of a way to show the event that he was describing (since it sounded like larrycav was mistaken as to what SelectedIndexChanged meant) as well as to show the distinction between when those events occur.
-
Apr 1st, 2015, 01:35 AM
#53
Registered User
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
 Originally Posted by jmcilhinney
I was suggesting that you seem not to understand how Data Sources and typed DataSets work and you might benefit from a bit of an explanation.
Holy hell man you are a troll -- just tell the kid how to refresh a combo box. For such a professional, you don't seem to have common knowledge of a common situation. I came here from Google trying to find the answer and you are just toying with him. If he wanted an explanation, he would have asked -- he wants an answer:
Code:
form1_load(nothing,nothing)
is a simple answer and works -- but it's slow. Anyone else have an idea of just like, a line of code, to refresh the data and ONLY an answer with code?
-
Apr 1st, 2015, 06:03 AM
#54
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
 Originally Posted by dylanh724
Holy hell man you are a troll
You got me. I do it for kicks. It's got nothing to do with wanting people to use their brains and think for themselves, even if it's against their will.
 Originally Posted by dylanh724
If he wanted an explanation, he would have asked -- he wants an answer:
I did want an explanation and I did ask for it - repeatedly - but I never got an answer. I kept saying that we need more information to be able to provide a proper solution and that information was never provided. You get what you pay for.
-
Apr 1st, 2015, 08:21 PM
#55
Registered User
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
 Originally Posted by jmcilhinney
You got me. I do it for kicks. It's got nothing to do with wanting people to use their brains and think for themselves, even if it's against their will.
I did want an explanation and I did ask for it - repeatedly - but I never got an answer. I kept saying that we need more information to be able to provide a proper solution and that information was never provided. You get what you pay for.
I got it just fine: I understood his problem even in the subject header. It's very clear that he wants to know how to update the values in a bound control after the data is altered. It was obviously very clear or this wouldn't be the top of my Google search for the same issue.
-
Apr 2nd, 2015, 03:26 AM
#56
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
 Originally Posted by dylanh724
I got it just fine: I understood his problem even in the subject header. It's very clear that he wants to know how to update the values in a bound control after the data is altered. It was obviously very clear or this wouldn't be the top of my Google search for the same issue.
And I explained how to do that. In fact, just as in your case, if you think that calling the form's Load even handler directly is going to do it then you obviously already know how to do it too, because you must have code in the Load event handler that already does it. The issue was that someone wanted to know WHERE to put the code and that is not something that anyone can simply pluck out of the air. Where you put code depends on circumstances and if you're not prepared to describe those circumstances then you're not going to get an answer that isn't conjecture, which I'm not prepared to waste my time providing.
-
Oct 10th, 2016, 05:23 PM
#57
New Member
Re: [RESOLVED] refresh combobox values after updating its datatable and adapter
I realize this thread is old, but I had a similar problem, and I tried all the solutions here as well as .invalidate, .createcontrol, .refresh, .performlayout, and more without success, so I wanted to leave a note as to the solution I found:
I was reading XML data to create a string array, and binding that as the datasource of a combobox. The combobox was not updating when I did this, however. No items or indexes were available, and even if I set the .text property, which was available, my setting was getting strangely overwritten at some indeterminate point after exiting the routine.
In stepping through it multiple times, I eventually realized the combobox was contained on a tabpage that was getting removed when the code started, and later re-added. The data binding was not happening until the tabpage was re-added to the tabcontrol, and it was both raising the selectedindexchanged event at that point, and changing my text.
Hope it helps someone.
In other news...jmcilhinney, you have the patience of a saint. I don't know how you deal with shenanigans like those above without completely losing your biscuit. Good form!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|