/// <summary> /// itemgrid stuff. gets cell data and updates the _currentAbility ComponentAbilityWrapper type. /// is invoked when the row is changed in the itemgridUC. /// </summary> /// <param name="rowNum"></param> /// <param name="e"></param> private void OnRowChanged(object rowNum, EventArgs e) { int row = (int)rowNum; ItemGridHeaderCell header = (ItemGridHeaderCell)itemGridUC1.GetHeaderCell(row); PropertyInfo pinfo = header.RowData; Type propertyType = pinfo.PropertyType; if (typeof(IList).IsAssignableFrom(propertyType)) { //Type listObjectType = itemGridUC1.RowData(row)[0].GetType(); IList list = (IList)Activator.CreateInstance(propertyType); foreach (var item in itemGridUC1.GetRowData(row)) { list.Add(item); } pinfo.SetValue(CurrentAbility, list); } else { pinfo.SetValue(CurrentAbility, itemGridUC1.GetRowData(row)[0]); //if is not a list, } }
/// <summary> /// This sets up the itemGrid control by /// Creating the headers /// Creating the footers /// Selecting the correct cell type /// Creating the cells and adding the data /// Adding them to the itemGrid control. /// </summary> /// <param name="abilitySD"></param> private void SetupItemGrid(ComponentAbilitySD abilitySD) { itemGridUC1.Clear(); Type t = _selectedComponentAbilityWrappers[_currentAbilityIndex].GetType(); PropertyInfo pinfo = t.GetProperty("Name"); ItemGridHeaderCell rowHeader = null; ItemGridFooterCell rowFooter = null; List <ItemGridDataCell> dataCells = new List <ItemGridDataCell>(); rowHeader = new ItemGridHeaderCell("Name", pinfo); dataCells = new List <ItemGridDataCell>(); rowFooter = new ItemGridFooterCell(new ItemGridCell_String(null)); ItemGridCell_String nameCell = new ItemGridCell_String(null); if (!String.IsNullOrEmpty(abilitySD.Name)) { dataCells.Add(new ItemGridCell_String(abilitySD.Name)); } itemGridUC1.AddRow(rowHeader, dataCells, rowFooter); rowHeader = new ItemGridHeaderCell("Description", t.GetProperty("Description")); dataCells = new List <ItemGridDataCell>(); rowFooter = new ItemGridFooterCell(new ItemGridCell_String(null)); ItemGridCell_String descCell = new ItemGridCell_String(null); if (!String.IsNullOrEmpty(abilitySD.Description)) { dataCells.Add(new ItemGridCell_String(abilitySD.Description)); } itemGridUC1.AddRow(rowHeader, dataCells, rowFooter); rowHeader = new ItemGridHeaderCell("Ability", t.GetProperty("Ability")); dataCells = new List <ItemGridDataCell>(); rowFooter = new ItemGridFooterCell(new ItemGridCell_AbilityType(null)); if (abilitySD.Ability != null) { dataCells.Add(new ItemGridCell_AbilityType(abilitySD.Ability)); } itemGridUC1.AddRow(rowHeader, dataCells, rowFooter); rowHeader = new ItemGridHeaderCell("AbilityAmount", t.GetProperty("AbilityAmount")); dataCells = new List <ItemGridDataCell>(); rowFooter = new ItemGridFooterCell(new ItemGridCell_FloatType(0)); if (!abilitySD.AbilityAmount.IsNullOrEmpty()) { foreach (float ammount in abilitySD.AbilityAmount) { dataCells.Add(new ItemGridCell_FloatType(ammount)); } } itemGridUC1.AddRow(rowHeader, dataCells, rowFooter); rowHeader = new ItemGridHeaderCell("CrewAmount", t.GetProperty("CrewAmount")); dataCells = new List <ItemGridDataCell>(); rowFooter = new ItemGridFooterCell(new ItemGridCell_FloatType(0)); if (!abilitySD.CrewAmount.IsNullOrEmpty()) { foreach (float crew in abilitySD.CrewAmount) { dataCells.Add(new ItemGridCell_FloatType(crew)); } } itemGridUC1.AddRow(rowHeader, dataCells, rowFooter); rowHeader = new ItemGridHeaderCell("WeightAmount", t.GetProperty("WeightAmount")); dataCells = new List <ItemGridDataCell>(); rowFooter = new ItemGridFooterCell(new ItemGridCell_FloatType(0)); if (!abilitySD.WeightAmount.IsNullOrEmpty()) { foreach (float weight in abilitySD.WeightAmount) { dataCells.Add(new ItemGridCell_FloatType(weight)); } } itemGridUC1.AddRow(rowHeader, dataCells, rowFooter); rowHeader = new ItemGridHeaderCell("AffectsAbility", t.GetProperty("AffectsAbility")); dataCells = new List <ItemGridDataCell>(); rowFooter = new ItemGridFooterCell(new ItemGridCell_AbilityType(null)); if (abilitySD.AffectsAbility != null) { dataCells.Add(new ItemGridCell_AbilityType(abilitySD.AffectsAbility)); } itemGridUC1.AddRow(rowHeader, dataCells, rowFooter); rowHeader = new ItemGridHeaderCell("AffectedAmount", t.GetProperty("AffectedAmount")); dataCells = new List <ItemGridDataCell>(); rowFooter = new ItemGridFooterCell(new ItemGridCell_FloatType(0)); if (!abilitySD.AffectedAmount.IsNullOrEmpty()) { foreach (float affect in abilitySD.AffectedAmount) { dataCells.Add(new ItemGridCell_FloatType(affect)); } } itemGridUC1.AddRow(rowHeader, dataCells, rowFooter); rowHeader = new ItemGridHeaderCell("TechRequirements", t.GetProperty("TechRequirements")); dataCells = new List <ItemGridDataCell>(); rowFooter = new ItemGridFooterCell(new ItemGridCell_TechStaticDataType(null, Data.GetllistoftTechSds())); if (!abilitySD.TechRequirements.IsNullOrEmpty()) { foreach (Guid techGuid in abilitySD.TechRequirements) { dataCells.Add(new ItemGridCell_TechStaticDataType(techGuid, Data.GetllistoftTechSds())); } } itemGridUC1.AddRow(rowHeader, dataCells, rowFooter); //rowHeader = new ItemGridHeaderCell("MineralCosts", t.GetProperty("MineralCosts")); //dataCells = new List<ItemGridDataCell>(); //rowFooter = new ItemGridFooterCell(new ItemGridCell_MineralDictionary(null, Data.GetListofMineralSds())); //itemGridUC1.AddRow(rowHeader, dataCells, rowFooter); itemGridUC1.HardRedraw(); //itemGridUC1.SoftRefresh(); }