Add column dynamically #218
-
|
I'm new and need help. I need to dynamically add a column to a table when the user requests it, but the data object I'm binding to doesn't have the corresponding property. In that case, the new column in the table will still be bound to the data object, but because there’s no matching property it will only show the object's ToString() result. Any suggestions on how I can bind that column to the object I want? Additionally, I tried dynamically adding a TableViewTextColumn and assigning it a converter. I can get the bound data object in the Convert method and use it to map to other storage, but ConvertBack only provides the user’s input string for that column, so I can’t get the data object to map back. This approach currently doesn’t work. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
|
@ipevo-brooks Can you share a code snippet or examples so we can see what's going on in case this didn't help you? I'm not really experienced in this, but here's some things I have in mind:
Apart from this, I tried replicating what I think is trying to achieve in this gist: https://gist.github.com/Georgios1999/776579aaae8f854bb2f0460ffd5ad023 In order to dynamically add an item and access its contents when changed, I don't think you need to use public void AddDynamicFieldIO()
{
var item = new Item { Name = "Dynamic Item", Quantity = 1 };
item.PropertyChanged += (s, e) => Item_PropertyChanged(null, null, item);
ViewModel.Items.Add(item);
}The string? name = item.Name ?? String.Empty;
Title.Text = name;Let me know if this is the solution you were looking for! Otherwise, we'll wait for @w-ahmad's answer so I can also figure out the documentation for this. |
Beta Was this translation helpful? Give feedback.
-
|
@ipevo-brooks This seems like a similar case to #176. If so, please refer to the solution I mentioned here: (#176 (reply in thread)). Let me know if it helps resolve your issue. |
Beta Was this translation helpful? Give feedback.
-
|
I built a simple demo to show my current issue. Using a dictionary as the data object does let me display dynamic data objects. But I also need to update the data, so I need a two-way binding converter. The problem is in the converter’s ConvertBack method. I currently can’t find a way to access the corresponding data dictionary. |
Beta Was this translation helpful? Give feedback.
-
|
I finally figured out a data binding method that fits my needs. Using index strings for binding was the key step. Thanks to everyone who answered my questions, you saved me. |
Beta Was this translation helpful? Give feedback.

@ipevo-brooks This seems like a similar case to #176. If so, please refer to the solution I mentioned here: (#176 (reply in thread)). Let me know if it helps resolve your issue.