I have added a valuelist column to my grid, with values from a dataset.
ErosionModel = grdGenericPercentBrand.DisplayLayout.ValueLists.Add("ErosionModel");
ErosionModel.ValueListItems.Add(erosionModelDataID, erosionModelRateName)
What event should I use to capture the erosionModelDataID of the valuelis from that given cell? I need to populate other cells on the grid based on this value.
InitializeRow is likely the event you want to use. It's raised when the row is first added through data binding, and is raised again when the grid is notified that the underlying data object was changed. The Value property of a cell in your column will contain your data key value ("erosionModelDataID" in your case).
By the way, the code you've included here creates the value lists and stores it in the grid's ValueLists collection, but doesn't assign it to any columns of the grid. You'll have to set a column's ValueList property to establish that association, assuming you haven't already done so.
here is my complete code...(The value list are on a per cell level in the one column (each cell has different values). My question is below the code.
My code:
private void ErosionModelComboBoxLoader() { // Scan through the ErosionModel column // add the dropdownlist with value ErosionModel // with ... // so the user can pick one of these value foreach (UltraGridRow row in grdGenericPercentBrand.Rows) { ValueList ErosionModel; int geographyID = int.Parse(row.Cells["GeographyID"].Value.ToString()); if (!grdGenericPercentBrand.DisplayLayout.ValueLists.Exists("ErosionModel")) { ErosionModel = grdGenericPercentBrand.DisplayLayout.ValueLists.Add("ErosionModel"); //scan throw the table tblErosionModelData and pick the right items for (int index = 0; index < tblErosionModelData.Rows.Count; index++) { object erosionModelDataID = tblErosionModelData.Rows[index]["ErosionModelDataID"]; string erosionModelRateName = tblErosionModelData.Rows[index]["ErosionModelRateName"].ToString(); int erosionModelDataGeographyID = int.Parse(tblErosionModelData.Rows[index]["GeographyID"].ToString()); if (geographyID == erosionModelDataGeographyID) { // Add this item to the ValueListItems of the ErosionModel ComboxBox ErosionModel.ValueListItems.Add(erosionModelDataID, erosionModelRateName); } } } row.Cells["ErosionModel"].ValueList = grdGenericPercentBrand.DisplayLayout.ValueLists["ErosionModel"]; } }
Question:
As you can see, there are two columns in each valuelist ( erosionModelDataID, erosionModelRateName). How do I get the value of the erosionModelDataID when the user selects from the valuelist for that given cell.
Btw, as per Infragistics examples, I thought I would be using the "CellChange" event of the grid to handle this?
e.g.
if ( "ErosionModel".Equals( e.Cell.Column.Key ))
{
//Do something (this is where I need to get the value from erosionModelDataID column of the Valuelist. However, I can't seem to reference the valuelist, is my scope off?
}
peryan77 said:How do I get the value of the erosionModelDataID when the user selects from the valuelist for that given cell.
CellChange is the appropriate time to respond to user input, if you want to react as soon as the user selects an entry but before the cell is taken out of edit mode. When this event is raised, the cell's Text property has been changed, but its Value hasn't. This means you need to look up what the corresponding value would be for that text. The easiest way to do this is to use the ValueListResolved (the ValueList that is actually being used; this works if you're setting a ValueList at the column level instead of the cell level) and to use its GetValue() method:
if (e.Cell.Column.Key == "ErosionModel"){ IValueList vl = e.Cell.ValueListResolved; int indexOfItem = 0; object val = vl.GetValue(e.Cell.Text, out indexOfItem); if (val != null) { // Cast "val' to a the data type of your data value // Perform the action you want based on this data value }}
I think the problem is in my loader,
This line of code seems to prevent me from adding another valuelist in the same column after the first one. However, if I remove it then I get a Key already exists error, so it seems I can add only one.
if (!grdGenericPercentBrand.DisplayLayout.ValueLists.Exists("ErosionModel"))
My question is,
How do I get a ValueList for each row in a column? Or would the approach be to use one value list object with different values in it on a row by row basis?
You essentially are adding only one ValueList to your grid, which you're reusing across all cells in a column.
What it sounds like you want is a different ValueList based on some other value. You should set the key of that ValueList based upon whatever value you're using to build the ValueList.
Alternately, you can avoid adding the ValueList to the control's ValueLists collection in the first place, and instead associate each cell in your column with a new ValueList when you need it. The downside to this approach is that you might duplicate similar ValueList instances.
By the way, I suggest moving the logic you have in your "loader" method into the InitializeRow event handler instead. That way, you can avoid having to loop through all the rows in the grid, and you can easily change what ValueList to use whenever you change the value you're using to determine what data to load into your ValueList.
So here is my approach, let me know if it makes sense,
I have a datatable in memory, e.g.
GeographyID, ErosionModelDataID, ErosionModelName
In my grid I have a column called GeographyID,
In my grid I add a dropdown column and I need to populate each dropdown with values from the datatable where geographyID are equal.
If I understand,
In the initalize row event I can add
ValueList ErosionModelValueList = new ValueList( );
Then load value list by using the row's geographyID to grab the related records from the datatable.
Would this work if the Valuelist name is the same for each row, along with the same column names of the valuelist?
peryan77 said:Would this work if the Valuelist name is the same for each row, along with the same column names of the valuelist?