Better constructor, adding listviewitem object to listview.items collection

Sharing to you a simpler way to add a listviewitem object compared to creating an instance from the items.Add() method and adding subitems to the instance until the columns are completed.

ListViewItem item = new ListViewItem(new string[13] {
entity.ItemID.ToString(),
entity.Name.ToUpper(),
entity.Description,
entity.Code,
entity.Remarks,
entity.Size,
CommonFunctions.ReformatToDecimal(entity.Stock, Globals.SystemSetting.InventoryDecimalDigit),
CommonFunctions.ReformatToDecimal(entity.SellingPriceBeforeVAT, Globals.SystemSetting.InventoryDecimalDigit),
CommonFunctions.ReformatToDecimal(entity.MovingCost, Globals.SystemSetting.InventoryDecimalDigit),
brandName,
location,
entity.ItemUnit.ItemUnitName,
CommonFunctions.ConvertBoolToEnglish(entity.Active)});

item.Tag = entity;
listViewItem.Items.Add(item);

 

Just pass an array of strings to the constructor.

One thought on “Better constructor, adding listviewitem object to listview.items collection”

Leave a Reply to Ralston Arsaga Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.