I have a grid set up with some cells set to style = dropdownvalidate with some valuelists behind them. They work perfectly unless I set a value at run-time before showing the grid. If I do this, and you try to change the value using the dropdown, it will change but then after the cell loses focus, the value reverts back to the original. I've messed with this for a while now and am stumped.
It's tough to sy without seeing it in action. But usually, if the cell reverts to the old value, it's cause of a data type mismatch of some kind. Like if the user enters a string value into a numeric column and the ValueList fails to find a match, the data source will reject the value.
If that's not very helpful (and I suspect it probably isn't in this case), then I recommend that you try to reproduce the issue in a small sample project and Submit an incident to Infragistics Developer Support so they can check it out.
In this case, I'm the user :) as this is still in development. That being said, I'm not entering anything, I'm selecting from the list, so I don't think it was be a datatype problem. Also, as long as I don't set the value before showing the grid, the selection will 'stick' just fine. I'll see if I can piece together a sample project, in the mean time, here is a couple of snippets of code that might give you a clue as to where I have gone wrong.
This is how I assign the valuelist to the cell, in the InitializeRow handler. It checks to see what the value is in the first column, and then assigns the appropriate valuelist. The commented out line is where the problem begins. Like it is here, the valuelist will work as expected and keep your selection. If I uncomment this, the correct item will display when I show the grid, but will then revert back to the original if I try to change it.
If e.Row.Cells(0).Value = "LocationId" Then e.Row.Cells(1).ValueList = LoadValueList("Location") 'e.Row.Cells(1).Value = _locationId e.Row.Cells(1).Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownValidate
This is how I load the valuelist, the data is being pulled from another class that holds the datatables with the lookup data I use. The tables have two columns, and Id (int) and Name (varchar).
Private Function LoadValueList(ByVal ListType As String) As Infragistics.Win.ValueList Dim vlLoad = New Infragistics.Win.ValueList Dim _dt As New DataTable _dt = LookUpTables.GetTable(ListType) For ix As Integer = 0 To (_dt.Rows.Count - 1) vlLoad.ValueListItems.Add(_dt.Rows(ix).Item(0), _dt.Rows(ix).Item(1)) Next Return vlLoad End Function
Okay, this makes perfect sense, then. You are setting the Value of the cell inside the InitializeRow event. So you are constantly overwriting it.
You are probably expecting that the InitializeRow event only fires once, but that is not the case. This event fires every time a cell value changes. It's designed that way so that if you are coloring a cell based on the value or changing a ValueList based on another cell's value, it works every time the values change.
So if you want to initialize the value of a cell, you either need to check e.ReInitialize so that you only do it once. Or else you need to do it outside of the InitializeRow event.
No, that is real code, the line above it is where it is checking the other Cell Value.
If e.Row.Cells(0).Value = "LocationId" Then e.Row.Cells(1).ValueList = LoadValueList("Location")
The LoadValueList function creates and passes back a ValueList based on the string that was passed in. There are 5 other If statements checking for the other types that may be used.
Oh, okay. This line threw me off:
e.Row.Cells(1).ValueList = LoadValueList("Location")
But I guess that was just for posting, not your real code. :)
The ValueList(s) are based on row specific information. Depending on what Value is in Cell(0) a ValueList is loaded in Cell(1). In the code snippet above, I only show one of the loads, for Locations. There are 5 other ones for Employees and several other 'Types' lists.
Hi Chip,
Out of curiosity... why are you populating the ValueList inside of InitializeRow, anyway? It doesn't appear that you are populating the ValueList based on any row-specific information. So it seems like you could just populate a single ValueList and attach it to the whole column rather than creating a new one for cell.
I knew it was something that I was missing, and Yes, I did think that a row would be initialized just once!
I used the e.ReInitialize and it is working perfectly now. Even better and the valuelists are not being reloaded ever time I change a cell value now! Thanks for your help and keep up the great work.
Chip