I have a grid in a C# winform app that when I initialize it, I set the property of a column to this:
e.Layout.Bands[0].Columns["MyURL"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.URL;
Now I've read where whatever is the cell content for that cell will be given a URL styling so I assume I need to form the link before the row is painted since I am taking cell data and appending it to this link (in a querystring).
I was trying the InitializeRow event with this code but it hasn't been working.
string
myId = e.Row.Cells["MyURL"].Value.ToString();
e.Row.Cells[
"MyURL"].Value = http://mywebsite.com/test.asp?id= + myId;
Do I need to use a different event here?
The InitializeRow seems like an excellent place to do this.
What's not working?
One odd thing I notice about your code is that you are reading from the same cell you are writing to. So this isn't going to work, because the second time the InitializeRow event fires, you will end up building the string using the entire string as the ID.
Hmmm, I'm confused on what to do then. I need to treat the value coming out of the database as a querystring item. I don't really want to alter my SQL call to create the necessary URL for the grid to use as it's value. Isn't there a way to take the database field value and wrap all that HTML around it then have that be the URL value for the link?
Yes, you can do this. But you don't wan to overwrite the query ID number in the cell, you need to maintain it.
What I recommend is that you use the InitializeLayout event of the grid to hide the column that contains the ID and then add an Unbound column and set it's Style to URL.
Then you can use InitializeRow to set the value of the cell in the unbound column without overwriting and losing the value in the ID column.
I got the column added with the code below. However, when trying to set the value for each cell I get this error:Value property can not be assigned while beforecellupdate event is in progressHere is my code:In my InitializeLayout event:myGrid.DisplayLayout.Bands[0].Columns.Insert(e.Layout.Bands[0].Columns.Count, "myURL");myGrid.DisplayLayout.Bands[0].Columns["myURL"].Header.VisiblePosition = 0;myGrid.DisplayLayout.Bands[0].Columns["myURL"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.URL;
In my InitializeRow event:string param = e.Row.Cells["queryStringParam"].Value.ToString();e.Row.Cells["myURL"].Value = "http://www.myurl.com/myurl.aspx?" + param ;
This error message indicates that you are trying to set the Value of a cell inside the BeforeCellUpdate event. So I doubt this code is causing that, it must be code inside BeforeCellUpdate. Are you sure you are using the right event here?