DataGridView Refresh from child Form

Dear All,

I am currently developing a Till application.  I have a main form which a toolbar where admin users can create/Update operators. When they select the tool bar option, it opens another form with a list of operators in a datagridview using the following code

Dim myForm As New frm_operatorList
myForm.ShowDialog(Me)

All works fine but i want to be able to update operator details, so i added a double click event to open another form and display the operator details using the showdialog method. That works fine and after Ive updated the operator details, I try and refresh the datagrid in the previous form but nothing as the data remains the same!

If i using the following code to show the list of operators, it all works fine

Dim myForm As New frm_operatorList
myForm.Show()

Why is it doing this?? is it because im creating a child from a child using the ShowDialog??

Please help as its driving me NUTS!

Thanks in advance

martmanworkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeCruiserCommented:
In such a scenario, i do the following.

Dim f as new frmNewOperator
f.showdialog
f.dispose
btnRefresh.performclick


in the btnrefresh, i reload the datagrid.
0
martmanworkAuthor Commented:
Thanks for the help but that didnt work.

is the btnrefresh in the parent form containing the list of users i wish to amend??
0
CodeCruiserCommented:
What is the structure of your application? You open a child form from main form which displays the datagridview. Then you open the second child form. Is the second form open from the first child or the main form? Is the data displayed in child 1 being held in child 1?
0
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

martmanworkAuthor Commented:
I have a main form (Basket) which opens a child form (OperatorList) which contains the datagridview i wish to update when i update the operator details. The UpdateOperaterDetails form is a child from the OperatorList Form NOT the basket.

For all the child forms, i am using showdialogue

Thanks
0
CodeCruiserCommented:
So the refresh button should be on the OperatorList form. I wrote that code to just demonstrate it. It does not mean you copy that code and run the project because you would need a refresh button with some code written in its click event to refresh the data. You could also do some thing like.

dim f as new UpdateOperatorDetails
f.showdialog
f.dispose
dTable.clear
dim dbadp as new sqldatatableadapter("Select * from Table", "connectionstring")
dbadp.fill(dTable)
dbadp.dispose

Note that this code again is to just give you an idea.
0
martmanworkAuthor Commented:
sorry but that still doesnt work.
bit confused as your code says that i should showdialog then immediately dispose of it after ive created the form?

Ive created a sub on the list operators form which reloads the datagidview.  When i update the data in the updateoperator form i call the sub in the operatorlist form. Surely that should work but no luck.

The only way i can get it to work if is i just use form.show when i open the operatorlist form! WHY???
0
Priest04Commented:

TTo the point of application performance, it is not a good idea to reload all the data, just because you have updated only one record. This can be unnoticeable when there are not many records, but if there are thousand or few thousand, then it can be cumbersome. So, what I would recomment as a good practice, is next (I will post only explanations):

- in the form details, pass the current info of the operator in a constructor, and update controls with this info to be presented to user
- after the user changes data, you can do update in two ways:
  -  if you have datagridview that is bound to a datatable, and you have a functional tableadapter/dataadapter, then you can pass the updated data back to the frm_operatorList, change the data in the datagridview manually, and call the adapter;s update method.
  -  if datagridview is unbound, or you dont have a functional tableadapter/dataadapter created, then you can update data on this form with a simple Update query, and after you have done, return the updated data to the frm_operatorList and change the data in the datagridview manually
  In both examples passing data will be done by creating public properties on a frm_operatorList, which yuo can access it after the line

Dim f as new frmNewOperator
f.showdialog
' access properties here
Dim name as string = f.OperatorName ' public property

You can also create a class called Operator, and have a public property in frm_operatorList of Operator type, which can easy the access of information.

frm_operatorList should be opened modelless
frmNewOperator should be opened modal
0
martmanworkAuthor Commented:
Thanks for the info but i do not want to open the operatorlist modeless as i want it to remain focused and on top.

It still doesnt answer my question about why it works fine if i open it modeless compared to modal?
0
CodeCruiserCommented:
If there are thousands of rows, its not a good practice anyway to pull them all into memory in a dataset.
0
CodeCruiserCommented:
It really depends on your approach to updating and not that whether its open modal or modaless.
0
CodeCruiserCommented:
>bit confused as your code says that i should showdialog then immediately dispose of it after ive created the form?

The difference between Show and ShowDialog is that Show displays the form and continues the execution of the main form. Showdialog not only blocks access to the rest of the interface, it also halts execution at the showdialog line of code. So the dispose line of code would only be executed when you close the dialog form.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
martmanworkAuthor Commented:
Then tell me why it works if I use the show method rather then the showdialog? Surely if it was my update method, it wouldnt work at all??

I know that there are not 1000's of row or ever will be, so im not too worried about that
0
martmanworkAuthor Commented:
Thanks CodeCruiser! it makes sense now, thank you for your help!
0
CodeCruiserCommented:
Glad to help.
0
Priest04Commented:
True point that you should be careful with what you show on the screen, codeCruiser, altough I have never met with financial application (windows forms) that displays articles, and doesn't display more than a thousand articles in a grid. YOu cannot expect a user to behave like you would want him to, a user can filter data, or doesn't want to, and will display all of them, and you need to make your application perform better as much as you can.

One of the main differences between SHow and ShowDialog, is that diposed method on dialog form is not called after you close it, like is the case with modal form. This allows you to access forms properties after the form is closed. I dont see the reason why it wouldn't work, and I never use an approach you are using, so I cant tell you want exactly is wrong with it. How do you update data in a frmNewOperator?
0
CodeCruiserCommented:
The developer, as said above in a post by the asker, knows how many rows may be loaded. For example, if i run a query to fetch only top 75 rows in a form and do not provide any way for user to load rows than that then the user is behaving the way i want him. Not all windows forms apps are financial applications by the way.
The approach i mentioned initially, to call the refresh button click method, i use this approach myself in my applications. But i only load a fixed number of recent items in that refresh button click.
0
Priest04Commented:
Since I see you are strongly defending your point of view, I will leave my final words here. :)

>> The developer, as said above in a post by the asker, knows how many rows may be loaded.

You didnt know that when you post your advice, so you cannot make this as an argument

What a developer should have in mind when creating application, is to create an efficient code. If you have a different code to load up to 100 rows, different code for up to 500 rows, different code for up to 2000 rows, etc, you will end up in a mess code. An efficient code for 5000 rows is also efficient code for 100 rows. Any good author of books about database access will tell you that fetching rows from database just because you have updated one row is a bad choice. This is something that is not arguable. I never said your code is not going to work, I just wanted to point out other approaches.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.