This is a migrated thread and some comments may be shown as answers.

Inserting Listview Items in a single line

1 Answer 218 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Veteran
Michael asked on 20 May 2020, 04:48 PM

This is more of a curiosity question. Sometimes I add a single item to my listview when I'm "Loading" or displaying other types of informational messages. Out of curiosity, is there a way to add an item and specify its column index all in one line? Right now I create the item, then specify its column index, and then set the text.

Say I have a RadListview created, columns already added are A,B,C,D,E. I want to simply add some entry under the Column "C" that says "Loading" but all in a single line of code.

This is not important, just curious if there is an easier way of doing it vs :

            lv.Items.Insert(0, new ListViewDataItem("Test") { Text = "Test" });
            lv.Items[0]["MyColumn"] = "Test";

Thanks!

 

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 May 2020, 08:30 AM

Hello, Michael,  

When in DetailsView, RadListView displays columns. You can set cell values to the items of RadListView using their indexers. The keys can be either the index of the column, the name of the column, or the column itself. To use these indexers, the item must have a valid owner e.g. it first has to be added to the Items collection of RadListView. That is why you need the two lines of code: one for adding the item to the control prior assigning its cell's values, so it will have its cells schema.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
ListView
Asked by
Michael
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or