Greetings,
I'm pretty new to the utlragrid control so bear with me. Using VB .Net I've added a grid to a form that saves a GroupKey and a CompanyID to a table in SQL Server. This portion I have working pretty well but then I was given a requirement to display the full company name on the grid as well which will not be saved to the database.
I figured an unbound column would be the best approach to this so I added one to the grid and added code to the AfterCellUpdate procedure to populate the company name column when a company id is updated or entered. Again this worked pretty well as long as I tabbed off the company id cell (another question I have but will post separately).
The problem I run into is when I open the form and retrieve records. The companyID displays as it should but the value for the Company Name column does not. I tried adding code to the cell change event to see once the companyID cell was populated if it would populate the company name column. However, this did not work.
So my question is what is the best technique to ensure the company name column populates based on the value set in the company id column.
Thanks
What you will need to do is use the Initialize Row event to populate your unbound Customer Name field. The After Cell Update event is not going to fire when loading your data. The Initialize Row event will fire for each row as it is being loaded into the grid for each row and it also fires between the Before Cell Update and After Cell Update events.
Depending on how you are getting your Customer Name I would use a data set relation to a linked customers table to display the customer name as an expression field (assuming you are using a data set). Then when the user changes the CompanyID field the expression will automatically update the calculated customer name field and you don't even have to worry about capturing events to update it manually.So instead of creating an unbound column in the grid you would create a calculated field in your data table that the grid is bound to. If you had a relation named FK_Customers the column expression might be parent(FK_Customers).CustomerName.
I'm doing something similar in a project and it has worked very well. Just a thought.
Hey Steve,
You were right on the money. I wasn't sure what you meant by a calculated field as I'm a newbie when it comes to Infragistic controls, so I took a different route to accomplish the job. However, the solution you suggested intrigues me, so if it isn't too much trouble could you provide a code sample of how you handle this situation.