Hi, I'm having trouble assigning values of non-standard type (not integer, string, or whatever) to a cell with a UltraDropDown grid.
I'll try to explain
My grid (Let's call it Grid1) is bound to a list of clsTypeA "Grid1.DataSource = New BindingList(of clsTypeA)" where:
public class clsTypeA
public Id as Long
public obj as clsTypeB
end class
Then I have an UltraDropDown (let's call it DropDown1) bound to a list of clsTypeB
public class clsTypeB
public Description as string
public overrides function ToString() as string
return Me.Description
end function
In Grid1, the column "obj" ValueList property is set to DropDown1.
I enter the main grid Grid1 in edit mode, add a new row... go to the cell for the value of "obj", open the dropdown and the list of objects is there. Then I select any of the objects, but the grid, instead assigning the object I selected to the property "obj" in the row, it assigns the string of "Description", so when I try to update the row I get an error "Cannot convert string to clsTypeB".
Why is it assigning a string value when the DataSource for the UltraDropDown is of clsTypeB and the value type for the column is also clsTypeB and not string?? Do I have to change any special property? what would be the way to accomplish what I'm trying to do?
I've tried also to set the Style property of the column to "DropDownList" to avoid editing (that's another problem) but then even if I select an object in DropDown1, no value is assigned to the cell...
I don't know if I explained myself very wel...
Hi,
The UltraDropDown is a multi-column dropdown. It's designed to let you pick a COLUMN in the dropdown that is associated with the cell in the grid. So when you select a row in the dropdown, it will, by default, take the value from the first column in the dropdown and try to put it into the grid cell. It's doesn't take the entire object representing the row and put that object in the cell.
But you can do this in a couple of ways.
1) Use the InitializeLayout event to add an unbound column to your UltraDropDown. Then, in the InitializeRow event, set the value of the unbound column cell to the ListObject property of the row. This gives you a c olumn that contains the clsTypeB object and you can use this unbound column as the ValueMember of the DropDown.
2) Instead of using an UltraDropDown, use a BindableValueList and set the ValueMember to BindableValueList.USE_LISTOBJECT_AS_VALUEMEMBER
Hello Mike,
I am using NetAdvantage 10.2 Win CLR2x. (WinForms)
I have the very same problem as described above. I do have to use a UltraDropDrown.
Your suggested solution 1) does not work for me. Within the ultraDropDown1_InitializeRow - Event, I cannot assign the Row.ListObject to the Cell-Value: InvalidCast Exception. It has to implement IConvertable. If it does - the ListObject is casted to String.
However your post gave me a hint for the right solution: The class used in the UltraDropDown uses an additional property which just returns this. This property can be used as the UltraDropDown's Value Member - everything is working fine now.
Of course it is "not so very nice" to implement some display hooks at the very bottom of the application. Maybe I am missing sth?
A complete sample file:
using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Windows.Forms;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
namespace UITest
{
public class
Shipment
public int ID { get; set; }
public int Price { get; set; }
public Adress Adress { get; set; }
}
public class Adress
public String Name { get; set; }
public String Zip { get; set; }
public string Street { get; set; }
public string City { get; set; }
//public object IHook
//{
// get { return this; }
//}
public partial class Form1 : Form {
List<Adress> adressList = new List<Adress>();
List<Shipment> shipmentList = new List<Shipment>();
Public Form1()
InitializeComponent();
Adress newAdress1 = new Adress {
Name = "xxx", City = "ccc", Street = "sss", Zip = "zzz"};
adressList.Add(newAdress1);
Adress newAdress2 = new
Adress
Name =
"xxx2"
,
City =
"ccc2"
Street =
Zip =
"zzz2"
};
adressList.Add(newAdress2);
Shipment newShipment = new Shipment
();
newShipment.ID = 10;
newShipment.Price = 22;
newShipment.Adress = newAdress1;
shipmentList.Add(newShipment);
newShipment =
new Shipment
newShipment.ID = 11;
newShipment.Price = 80;
newShipment.Adress = newAdress2;
private void Form1_Load(object sender, EventArgs
e)
ultraGrid1.DataSource = shipmentList;
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs
ultraDropDown1.DataSource = adressList;
//ultraDropDown1.ValueMember = "IHook";
ultraDropDown1.ValueMember =
"objValue"
;
ultraDropDown1.DisplayMember =
"Name"
//ultraGrid1.DisplayLayout.ValueLists.Add(valueList);
ultraGrid1.DisplayLayout.Bands[0].Columns[
"Adress"
].ValueList = ultraDropDown1;
private void ultraDropDown1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs
UltraGridColumn ugc = ultraDropDown1.DisplayLayout.Bands[0].Columns.Add("objValue"
);
ugc.Hidden =
true
//ultraDropDown1.DisplayLayout.Bands[0].Columns["IHook"].Hidden = true;
private void ultraDropDown1_InitializeRow(object sender, InitializeRowEventArgs
object
obj = e.Row.ListObject;
Adress adress = obj as Adress
e.Row.Cells[
"objValue"].SetValue(obj, false