Note that there are some explanatory texts on larger screens.

plurals
  1. POListView programatically added columns shows type of item
    text
    copied!<p>I got a ListView in another assembly and want to add a column to it. The items in the listview are objects of a class in that assembly.</p> <p>When I add a column like this</p> <pre><code>var col : GridViewColumn = new GridViewColumn(); col.Header = "Header text"; list.View.Columns.Add(col); </code></pre> <p>the column appears but all rows in the listview have the name of the type of the item in that new column. Even when I change the value of the new column (<code>itemclass.Items[newColIdx] = "zz"</code>) this does not display. There is no data binding or cell templates involved.</p> <p>Why is that?</p> <p><strong>Edit</strong>: Maybe I can enhance the question: If a ListView.Items contains an array of class A - how do you control which things of A are displayed how in the GridView? I am in the need of reverse engineering here and DisplayMemberBinding is null so it does not use data binding AFAIK.</p> <p><strong>Bounty Question</strong>: When <code>ToString()</code> is called on every item (which represents a row), how is that mapped towards the columns of the GridView? How must I alter an item in the row so that the new column is filled?</p> <p>Special problem when trying to find this solution is that this runs in a JScript sandbox within a bigger C# .NET application and no debugging possibility is supplied other than using message boxes and reflection.</p> <p><strong>Edit</strong>: The problem is that I am writing a JScript which runs in a 3rd party .NET application and gives me the opportunity to do many things possible with .NET. This is a script adding features to a listview. I can access the listview and it is filled with database data by the 3rd party app. I do not know how it does that. I can programatically add custom rows with custom content (not DB related). But when I add a custom column I do not seem to be able to se its value in den rows.</p> <p>The added rows are of a type <code>3rdParty.ListRow</code> and contain a property <code>Items</code> to which I assign a string array. The values of the array are displayed in the representative columns - but not in the added columns. There I only get the text <code>3rdParty.ListRow</code> which is because <code>ToString()</code> was called on the ListRow.</p> <p>So: How can I tell the new columns (e.g. index 5) to display <code>ListRow.Items[5]</code> and not <code>ListRow.ToString()</code>? I liked to do it the same way the already existing columns do it seems that all the properties Alex mentioned are undefined there. How would I set <code>DataMemberBinding</code> to achieve mapping to <code>ListRow.Items[5]</code>?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload