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
The unbound column approach will work, but that's doing things the hard way.
A much easier way to do this would be to provide a dropdown list in the existing bound column.
I assume that you have a table of company IDs and company names. What you do is load that data and bind it to either a BindableValueList or an UltraDropDown control. Either way, you set the ValueMember and DisplayMember on the list to the CompanyID and CompanyName fields respectively.
Then you set the ValueList property on the grid column to the ValueList/UltraDropDown control. And that's it. The value list will automatically translate the values into display text in the grid, but still save the IDs to the underlying data source.
Hi Mike,
I have two columns to deal with. One is the company IDs. This one is already configured to be a valuelist. This is working quite well. Then I was given the requirement to display the company name as well in a second column based on what is selected in the company id column.
If a BindableValueList can accomplish this, can you provide an example of how it would be done?
Hi,
My solution was to have the CompanyID field display the Company name instead of the CompanyID.
Do you really need to display both? Does the user really care what the company ID is? In most applications, ID numbers are hidden - the user only cares about the name.
If you need to display both the ID and the name, then the unbound column approach is the better way to go. There's no way to display both in the same cell.
But if your column is already using a ValueList, then this is even easier. Then all you have to do is set the DisplayMember. And you will probably want to set the column.Header.Caption of the grid column to display something like "Company Name", instead of "CompanyID".
Sad to say but yes it is a requirement. I'll try Steve's suggestions to work around the issue I'm having currently.
Thanks for the help.