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
tootallOP2y 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
tootallOP2y 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
tootallOP2y 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
tootallOP2y 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
tootallOP2y ago
BlazeBin - lempulpxncoa
A tool for sharing your source code with the world!
tootall
tootallOP2y ago
thanks I'll check it out when I have a minute
tootall
tootallOP2y 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
tootallOP2y 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