Hi, I am wondering how I can set the index of a ValueList that is assigned to a WinGridCell. For example I've assigned a list to the cell at the InitialiseLayout eventgrid.DisplayLayout.Bands[0].Columns["ColumnName"].ValueList = ValueList object.Which is all well and good.So basically when a user goes to enter a new row, I want to set the SelectedIndex of that valuelist in the cell to 0.I have tried,
private void grid_AfterRowInsert(object sender, Infragistics.Win.UltraWinGrid.RowEventArgs e) { try { switch (e.Row.Band.Index) { case 0:
e.Row.Cells["ColumnName"].ValueList.SelectedItemIndex = 0;
}
}...But this errors by saying the ValueList is NULL, but as you see, I've assigned the ValueList at the InitialiseLayout event. Any help would be good. ThanksChris
Ok as I was reading my post, I worked out I was assigning the ValueList in the InitialisedLayout event to the "column" object and checking in the AfterRowInsert event checking against the cell object, which is why it was a NULL, I am guessing that you need to work with the column object and not the cell in this case?
Hi Chris,
You can get the cell's ValueList using the ValueListResolved property on the cell. But setting the SelectedIndex will not work. The ValueList serves the entire column, so no property you set on the ValueList will affect the cell in the AddNewRow or any other row. It can't, because the grid has no way of know which row you want to affect.
What you have to do is set the Value property on the cell. If you want the dynamically get the first item on the ValueList and use it's DataValue, then what you would do is get the ValueList using ValueListResolved, then get the first item and use it's DataValue.
ValueList vl = e.Row.Cells["ColumnName"].ValueListResolved;
e.Row.Cells["ColumnName"].Value = vl.ValueListItems[0].DataValue;
Thanks for the response Mike.However I you cant cast the object ValueListResolved to ValueList, its needs to be cast to the Interface IValueList Which the interface doesn't expose the method of ValueListItem. So therefore usign your lines of logic I got it to work with
IValueList vl = e.Row.Cells["ColumnName"].ValueListResolved;
e.Row.Cells["ColumnName"].Value = vl.GetValue(0);
I will mark the answer as correct still.Thanks Mike.
Oh, I assumed you were using a ValueList, but you must be using an UltraDropDown.
Your solution will work for both cases, so that's even better.