C
C#2y ago
tootall

❔ ObjectListView showing blank rows

Hi all. I'm new to C# and making VSTO addins, please bare with me! I'm using the add-in control ObjectListView (https://objectlistview.sourceforge.net/cs/index.html) to create a list of categories as part of VSTO Outlook Add-in.
I've added the control to my form (a user control) and set the following properties: - View: List - Show Groups: False - Columns: One column added, AspectName "Category.Name" (also just "Name" was tried, without success). Here is the code when the user control loads
private void MyUserControl_Load(object sender, EventArgs e)
{
Categories categories = GetCategories();

List<Category> myCategories = new List<Category>();

foreach (Category c in categories)
{
myCategories.Add(c);
}

this.objectListView1.SetObjects(myCategories);

}
private void MyUserControl_Load(object sender, EventArgs e)
{
Categories categories = GetCategories();

List<Category> myCategories = new List<Category>();

foreach (Category c in categories)
{
myCategories.Add(c);
}

this.objectListView1.SetObjects(myCategories);

}
I had thought that maybe the Objectlistview didn't like the default collection of the categories so that's why I made a new List<Category> collection The category collection is obtained via
public Categories GetCategories()
{
Categories categories = Globals.ThisAddIn.Application.Session.Categories;
return categories;
}
public Categories GetCategories()
{
Categories categories = Globals.ThisAddIn.Application.Session.Categories;
return categories;
}
when I run this I get six empty rows, which matches the number of categories on the outlook account (see picture). Not sure what I'm doing wrong, I followed the guide the best I could. The Category.Name method should be returning a string so I don't think that's the problem. Must be missing something obvious as this control is supposed to be easier to use than a listview.
16 Replies
techdevoscar
techdevoscar2y ago
List(either non-generic or genetic types) don't notify the UI that the property has changed. Try using ObservableCollection Full disclosure, I'm new at this as well and I've been studying this the past few hours 😆 Alternatively you might be able to useINotifyPropertyChanged but an ObservableCollection might be easier.
tootall
tootall2y ago
thanks for the reply! so you're suggesting using ObservableCollection in place of List?
techdevoscar
techdevoscar2y ago
Yeah, give that a shot. They have the same interface so they are interchangeable.
tootall
tootall2y ago
yea I did try it right now, same result, six blank rows 🙁 I should probably just try this out with a simple program and class just to see if I can get it to work that way.
techdevoscar
techdevoscar2y ago
How are you binding the data?
tootall
tootall2y ago
with this control you should just need to put the name of the property or method of the object into the column editor in the IDE. It generates the row directly from the object. (if I understand what your asking!) see here: https://objectlistview.sourceforge.net/cs/gettingStarted.html#:~:text=The%20first%20configuration,properties%20at%20once).
techdevoscar
techdevoscar2y ago
I'm not sure. Can I see the source code? I might be able to get a better idea on what you're working with
tootall
tootall2y ago
There's really not much more than what I've shown you Do you want me to just copy/paste it here?
techdevoscar
techdevoscar2y ago
Place it here: https://paste.mod.gg/
BlazeBin
A tool for sharing your source code with the world!
tootall
tootall2y ago
BlazeBin - lempulpxncoa
A tool for sharing your source code with the world!
tootall
tootall2y ago
thanks I'll check it out when I have a minute
tootall
tootall2y ago
well this very simple test worked no problem so I guess it has something to do with the Category object or collection thereof
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

List<Person> people = new List<Person>();

people.Add(new Person("Joe"));
people.Add(new Person("Mike"));

foreach (Person p in people)
{
Debug.WriteLine(p.Name);
}

objectListView1.SetObjects(people);
}
}

internal class Person
{
public string Name { get; set; }

public Person() { }

public Person(string name) => this.Name = name;
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

List<Person> people = new List<Person>();

people.Add(new Person("Joe"));
people.Add(new Person("Mike"));

foreach (Person p in people)
{
Debug.WriteLine(p.Name);
}

objectListView1.SetObjects(people);
}
}

internal class Person
{
public string Name { get; set; }

public Person() { }

public Person(string name) => this.Name = name;
}
techdevoscar
techdevoscar2y ago
Ohh sweet! Great job!
tootall
tootall2y ago
Let's not break out the champagne yet! I still need to find a solution for the actual implementation! A further update on this - The "Category" class appears to be an interface of an interface. using the .GetType() for an item of the Categories collection returns System.__ComObject, perhaps this is why it returns a blank string? If I create a simple class with a single string property and then take the Category.Name and save it the new class Name the objectlistview will display it. At this point I feel like I just need to create my own class and copy over the relevant information from each Category and use that instead. A bit of a PITA if I have to go back and forth between the Outlook category collection and my own.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ NullReferenceException Object reference not set to an instance of an object Billboard.UpdateHello, my name is Zorphix and I'm not so smart at C#. And I'm currently trying to add a billboard sc❔ Blazor Hosted - Client datatable with large datasetI have a table component (using MudBlazor) which accesses the server-side API endpoint and pulls (cu❔ How do I cycle through different observable collections within the same collection view?My current plan is to do something like: ``` List <ObservableCollection<TodoItem>> allTodoItems✅ I'm trying to understand WPF's source code. What is a WeakReferenceWeakReference is a class that probably has applications other than in WPF (in particular, I'm trying❔ Shortcut for selecting multiple lines on windowsHi, I want to select only lines 146, 150 and 154 in my project in order to copy them, is there a sho✅ Token present on Get but missing on Post using IdentityPasted images to show autos with breakpoints. Code present on Get but missing on Post. I'm not sure ❔ Watch on screen area and reactHi. How can I do it? I need to "watch" on specfic screen area and when eg cursor is in this area app✅ The name does not exist in current context. (forms)I simply may be too dumb but i cannot wrap my head why is this an error.❔ Docker issues with dotnet restorePlease read my Stackoverflow post.... I have been working on this for a couple of days now I can't f✅ Mathematical ExpressionsHi, for my university assignment, I am required to add complex expressions alongside my variables. T