I’m still struggling and haven’t found a better approach than the one I previously tried to delete a specific type across all LstTypes and refresh the view to display the default_type (ColumnType(0, 0), which represents a dummy object) for symbols whose instances were deleted?
Perhaps consider a contextual menu in the datagrid (right-click a row to delete the selected type), I’ll see if I can find the time, as this is not a task that can be done in a few minutes (even with the help of an AI).
I was able to solve this issue with ChatGPT’s help. I couldn’t directly access the DataGrid row representing the SelectedType to delete, but ChatGPT guided me to use VisualTreeHelper to locate and access it through the visual tree.
Here my final code:
def btnDelete_Click(self, sender, e):
try:
current_level = self.tabLevels.SelectedItem
if current_level is None:
return
# Get the type to delete from the selected symbol in current level
selected_type = None
for symbol in current_level.Symbols:
if symbol.SelectedType is not None and symbol.SelectedType != current_level.default_type:
selected_type = symbol.SelectedType
break
if selected_type is None:
forms.alert("Please select a symbol with a valid type to delete.")
return
for level_vm in self.DataLevels:
for symbol in level_vm.Symbols:
if symbol.SelectedType == selected_type:
symbol.SelectedType = level_vm.default_type
# Remove the type from this level's type list
to_remove = [t for t in level_vm.LstTypes if t == selected_type and t != level_vm.default_type]
for t in to_remove:
level_vm.LstTypes.Remove(t)
if to_remove:
level_vm.notify_property_changed("LstTypes")
except Exception as ex:
forms.alert("Error deleting type: {}".format(ex))