Author Topic: PropertySetDefinition with a List data type  (Read 195 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
PropertySetDefinition with a List data type
« on: May 08, 2024, 07:06:09 PM »
I have a tool for displaying and editing PropertySets which was working well until we added a definition with a List data type. I can get the list but I need to show it in a DataTable. I define the column as a DataType.List but have been unable to figure out how to actually use it in the table. When I add it when filling the table it just shows up as (Collection) but I need it to show the actual PropertySet current value. I had also thought that by using the List datatype the list would be shown as a dropdown to select another item in the list.
To save the List column data I use a Dictionary since there may be mor than one column of this type:
Code - C#: [Select]
  1.             var listDictionary = new Dictionary<string, List<string>>();
  2.  
As I loop through the definitions to create the columns I get the Name and the actual list of items:
Code - C#: [Select]
  1.  case Autodesk.Aec.PropertyData.DataType.List:
  2.      dtype = typeof(List<string>);
  3.      var thelist = (AEC.ListDefinition)prop.ListDefinitionId.Open(OpenMode.ForRead);
  4.      var items = thelist.GetListItems();
  5.      var dataList = new List<string>();
  6.      foreach (ObjectId item in items)
  7.      {
  8.          var j = (AEC.ListItem)item.Open(OpenMode.ForRead);
  9.          dataList.Add(j.Name);
  10.      }
  11.      listDictionary.Add(prop.Name, dataList);
  12.      break;
Then, when I get the actual PropertySet data assigned to an object fill the table rows:
Code - C#: [Select]
  1.                                 foreach (string s in GetPropDefs(property))
  2.                                 {
  3.                                     var d = propset.GetAt(propset.PropertyNameToId(s));
  4.                                     if (theTable.Columns[s].DataType == typeof(List<string>))
  5.                                     {
  6.                                         List<string> dd = listDictionary[s];
  7.                                         row[s] = dd; //How to display the actual value of s which is a member of the list?
  8.                                         continue;
  9.                                     }
  10.                                     row[s] = d; //This works for DataTypes int, double, string, and bool
  11.                                 }
  12.  
If I make the Column for the List as a string type, I can just assign the PropertySet Value, but then the list is ignored.

I'm drawing a blank on how to implement this. A Google search gives all kinds of answers on how to create the DataTable from a list but nothing on how to use a list with a DataType.List cell.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: PropertySetDefinition with a List data type
« Reply #1 on: May 09, 2024, 03:59:18 PM »
A bit of headway made ... I changed the DataTable column to be a typeof Dictionary<string, List<string>> so I can put the current value as the Key and the List as the value to be used in the DataGrid. However, when the DataGrid columns are auto-generated, the column with the Dictionary is created as a DataGridTextColumn. I think that what I am after is to have that column be a DataGridComboBoxColumn set with the cell set to the value and the selected item set the Key of the dictionary.

I believe I'm on the right track here, just really struggling on how to accomplish it. WPF, MVVM, c#  :uglystupid2:

Hanauer

  • Mosquito
  • Posts: 11
Re: PropertySetDefinition with a List data type
« Reply #2 on: May 09, 2024, 04:37:17 PM »
I have been using DataGridViewComboBoxColumn and getting satisfactory results.
If you could post part of the code of the final solution you arrived at, I would be grateful.

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: PropertySetDefinition with a List data type
« Reply #3 on: May 15, 2024, 02:43:18 PM »
Okay, more headway made. I finally realized that I needed a new class (PropList) to hold the list and the current value for the object. I have not yet been able to get the Combobox to display the list or current value. The DataTable is created properly, with the column for the List type created as a PropList type. Then in the Window the DataGrid's ItemsSource is set to the ViewModel's property for the DataTable. All the columns fill with the correct values, except that PropList column. One of the solutions I found in my searches says that adding this to the XAML should fix it:
Code - XML: [Select]
  1.                 <DataGrid.Resources>
  2.                     <DataTemplate x:Key="dataItemCellTemplate">
  3.                         <ComboBox SelectedValue="{Binding DataContext.CurrentValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
  4.                                    ItemsSource="{Binding DataContext.Values}"/>
  5.                     </DataTemplate>
  6.                 </DataGrid.Resources>
  7.  

Where CurrentValue and Values are the 2 properties of PropList. Then include this in the code behind for the AutoGeneratingColumn event:
Code - C#: [Select]
  1.             if (e.PropertyType == typeof(PropList))
  2.             {
  3.                 var col = new DataGridTemplateColumn
  4.                 {
  5.                     CellTemplate = (DataTemplate)PropData.FindResource("dataItemCellTemplate"),
  6.                     CellEditingTemplate = (DataTemplate)PropData.FindResource("dataItemCellTemplate"),
  7.                     Header = e.PropertyName
  8.                 };
  9.                 e.Column = col;
  10.                 return;
  11.             }
  12.  
But something is still amiss and I am at a loss on where to look.