I have an application that allows a user to search a SQL database for a store. The user types in a store name and clicks a button and another, seperate form pops up with a list of stores that match the name that was entered. The user can select one of the stores and the popup form closes and a grid on the main form is populated with data from the database about that store. This is all powered through calling stored proceedures on the SQL server rather than using a dataset and it works without issue. The problem I have is when the user edits a cell in the grid.
I have a RowEditTemplate set up in modal for the grid because the stored procedure gives back more information than the user needs to see, and they are only allowed to edit a few of the fields that they can see. When they click on a cell, the RowEditTemplate pops up and they can make and save their changes. I've added code to the save button to call an update stored procedure and populate the paramters for the procedure. This all works fine as well.
The problem is that when the user searches for another store, then the RowEditTemplate no longer works! Even if they select the same store from the search box! I've stuffed a msgbox into BeforeRowEditTemplateDisplayed to let me know when it is called, and it is not called after the user performs their second search. I have the grid setup to show the RowEditTemplate when the cell changes (OnCellChange), but for some odd reason, it does not want to dispaly the template after the second search is performed by the user.
Any thoughts as to why this might be occuring?
Thanks Matt. Spent whole sunday to figure this out. Shold have come here first thing.
Thanks a million.
Matt, you are my savior! Assigning the RowEditTemplate in the grid's InitializeLayout event works perfectly.
Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you for your brilliant insight!
I don't see why the DataMember property being null should matter, and I'm curious where you got a NullReferenceException when trying to access the RowEditTemplate (unless you were trying to access a property off of that). Perhaps what you could do is assign the RowEditTemplate to the band in the InitializeLayout event, which should fire each time to call SetDataBinding.
-Matt
I did some more troubleshooting and checked the RowEditTemplateResolved as well. It too came up null after the second search. Stepping through the code to fill in the grid, I found that the reference to the template was lost when I bound the grid to the DataView. The code I use for this is: Me.u_grdStoreData.SetDataBinding(dv, Nothing, True)
The dv variable is the DataView. I picked this code up from another site that said it was better to do it this way than using the DataBind method. (Me.u_grdStoreData.DataBind()) because this way I could hide the columns that in the DataView that did match the schema of the grid.
Could that middle variable ("Nothing") be the issue?
Thanks again for the advice and opinion. I followed your suggestion about checking whether or not the band's RowEditTemplate was null or not and I found something interesting.
The first time the user searches and the grid is filled, the RowEditTemplate exists. The second time the grid is filled, I get NullReferenceException when trying to check for the RowEditTemplate on the band.
I don't really want to create the RowEditTemplate dynamically every time the grid is repopulated, but that looks like the most expedient solution at the moment. Any last thoughts before I submit a sample to Developer Support?