Hi All,
First of all let me tell you i am having an MDI Application. where i am using Ultrawin toolbar. Using that i have created two buttons for two forms of my application. In one form i am having Infragistics Wingrid in which i am listing the list of all the employees. This form is for the display purpose and if any one wants to see details abt that emp they can double click perticular emp and its detail form get open.
Second form is the form from where i can add new employee.In my application its such that we have to provide button to open new form using ultra win toolbar.
Now when user runs the application by default the child form will be the form which display the list in wingrid. If the user wants to add new emplyoee he will click and open form.
Problem is when the save button get hit the data get saved in the database successully and that form gets close and focus come back on listing form but the grid is not getting refreshed and the new entry is not getting listed in the grid. To get that row in the grid i have to close it and open it again then only it come.
Can any one tell me how can i reload the grid????
Get the data again as you did in the first place and data bind the grid. However, You may consider another approach. Add the new item to the data that is already binded to the grid and put the save button in the grid form. I'm not saying that this approach is better. In this case you can refresh the data by grid.Rows.Refresh method.
Thats what i did but even after the process successfully finish to re assigning the data source to the grid it is not refreshing....means at one time its showing 10 rows now i have inserted one more and when that form get close at that time i am calling the procedure which will reload the data source to the grid but its not working...the grid remain same with the data it was containing
In the main form where i display the list of data on the first time there i fill the data source using following code
Private Sub frmAdvert_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
RefreshAdvert()
End Sub
Public Sub RefreshAdvert()
ultraGrdAdvertInfo.DataSource = objAdvert.GetDataAsTable
here objAdvert is a class and the code in there is as mantioned below
Get
GetAdvert()
Try
selectCMD.CommandType = CommandType.StoredProcedure
cnnAdvert.Open()
dstAdvert.Clear()
adaptAdvert.SelectCommand = selectCMD
adaptAdvert.Fill(dstAdvert,
"tblAdvertInfo")
cnnAdvert.Close()
MessageBox.Show(ex.Message,
"TempID", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
This is the code which i use to load grid in the first place now when the insert is done in other form i just write over there.
Private Sub btnSaveAdvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveAdvert.Click
---- Code to save the Data in DB
frmadvert.RefreshAdvert
End Sub.
Try that:
dim b as BindingSource = new BindingSource()
b.DataSource = ' Get the data
grid.DataSource = b
When you need to refresh:
grid.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.ReloadData)
Hey Korach,
Thanks for the reply....but will ask you to give me one more favour.
can you plz tell me where to use this code??????
It seems like you have provided two blocks if i am not wrong what i think is that i am suppose to put this two block in two places can you plz elobrate it a bit..
Thanks
Use the first block when you need to get the data for the first time. Use the second block when you need to reload the data and the grid has rows already.
I did it but its not refreshing the grid it remain as it was.
has it something to do with the calss which i use to call the procedure to assign the datasource. As i am using class to write all the procedure which deals with the data binding.so what i did is when i want to refresh the grid is
b.DataSource = objSearch.GetDataforGrid(StrQuery)
ultraGrdAdvertInfo.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.ReloadData)
and i call this procedure in the form from where i want to refresh the grid so it was like this
frmadver.refreshadvert(query)
but same result
Hey Mike,
As you told me i have uploaded a sample project on the Dev. Support for their look. I am also attaching the same project here also if you feel then plz look into it and check it.
In case you look the project then you need to create a table with the name tblAdvertInfo with the following fields.
AdvertID - int - primary key - set IS Identity on
AdvertTitle - varchar(100)
Media - varchar(50)
AdvertDetail - ntext
CostCentre - varchar(50)
UserName - varchar(20)
UpdateDate - date
Response - ntext
BranchLocation - varchar(50)
Regards
Hm, that's odd. I'm afraid I have no idea what's happening there, then.
Perhaps you can duplicate this behavior in a small sample project and Submit an incident to Infragistics Developer Support so they can check it out.
hey mike,
thnx for the reply...well i just went through your answer and u said if it work for controls on same form then it should work controls on other forms.
but mike untli i opt for the MDI application the grid is getting refreshed and reloaded in diff forms also.
its only the case when i put one form in MDI application and then try to reload it from other form then only its not getting reloaded.
I'm not sure exactly what the issue is, but if it works when the two grids are on the same form and does not work when they are on different forms, then my guess is it has something to do with the BindingContext. The DotNet BindingManager uses the containing control as the default BindingContext so that if you have controls on the same form inside the same container bound to the same data source, the controls will stay in synch. But controls in different containers will not.
So perhaps all you have to do is assign all of your controls to have the same BindingContext - perhaps use the BindingContext of the MDI Parent form.