Hi.
I currently use the following extension methods
public static partial class ListViewSubItemExtensions
{
public static void SetText(this ListViewItem.ListViewSubItemCollection self,
int columnIndex, string text)
{
while (self.Count <= columnIndex)
self.Add(string.Empty);
self[columnIndex].Text = text;
}
public static void SetText<T>(this ListViewItem.ListViewSubItemCollection self,
int columnIndex, T value)
{
SetText(self, columnIndex, value.ToString());
}
public static void SetText(this ListViewItem.ListViewSubItemCollection self,
ColumnHeader column, string text)
{
SetText(self, column.Index, text);
}
public static void SetText<T>(this ListViewItem.ListViewSubItemCollection self,
ColumnHeader column, T value)
{
SetText(self, column.Index, value.ToString());
}
}
the body of your loop would become:
ListViewItem myItem = new ListViewItem(grVO.currencyName);
if (grVO.exchangeType == "Buy")
myItem.SubItems.SetText(1, grVO.exchangeRate);
else
myItem.SubItems.SetText(2, grVO.exchangeRate);
lsvExchangeRate.Items.Add(myItem);
Regards,
Daniele.