M
mp
here i am able to make a function that can be reused
only the listview changes,
private void ClearCriteria()
{
ClearListView ( this.lvCriteriaList );
}
private void ClearStockWatchList ( )
{
ClearListView ( this.lvStockWatchList);
}
private void ClearListView(ListView lv)
{
for (int i = 0; i < lv.Items.Count; i++)
{
lv.Items.Checked = false;
}
}
to populate those two listviews however, i have two different functions
the objects filling the listview have different property names
not sure how i can do this with just one function and pass the listviews and
collections in
here's the first one
private void LoadCriteriaListIntoListview(List<Criteria > criterialist)
{
lvCriteriaList.Columns.Add("Criteria");
lvCriteriaList.Columns.Add("Code");
lvCriteriaList.View = View.Details;
lvCriteriaList.CheckBoxes = true;
ListViewItem lvitem;
foreach (Criteria criteria in criterialist)
{
lvitem = lvCriteriaList.Items.Add(new
ListViewItem(criteria.Value));
lvitem.SubItems.Add(criteria.Key);
}
int scrollbarWidth = SystemInformation.VerticalScrollBarWidth;
int borderwidth = SystemInformation.BorderSize.Width;
lvCriteriaList.AutoResizeColumn(0,
ColumnHeaderAutoResizeStyle.ColumnContent);
lvCriteriaList.AutoResizeColumn(1,
ColumnHeaderAutoResizeStyle.HeaderSize);
lvCriteriaList.ClientSize = new
Size(lvCriteriaList.Columns[0].Width
+
lvCriteriaList.Columns[1].Width
+ scrollbarWidth +
(borderwidth * 2), lvCriteriaList.ClientSize.Height);
}
so input arg is List<Criteria >
Criteria has two props, Key and Value
the other listview gets input arg of StockListCollection : List<Stock>
Stock has two props Name and Ticker
so the column headers have to be different
and the object types are different
and the property names are different
and one input is List<object> and the other is a class that derives from
List<object>
i'm not seeing an easy way to get away without two separate routines,
even though they are very similar in the rest of the function
i could factor out the resize code into a function but the filling part i'm
not sure?
thoughts?
thanks
mark
only the listview changes,
private void ClearCriteria()
{
ClearListView ( this.lvCriteriaList );
}
private void ClearStockWatchList ( )
{
ClearListView ( this.lvStockWatchList);
}
private void ClearListView(ListView lv)
{
for (int i = 0; i < lv.Items.Count; i++)
{
lv.Items.Checked = false;
}
}
to populate those two listviews however, i have two different functions
the objects filling the listview have different property names
not sure how i can do this with just one function and pass the listviews and
collections in
here's the first one
private void LoadCriteriaListIntoListview(List<Criteria > criterialist)
{
lvCriteriaList.Columns.Add("Criteria");
lvCriteriaList.Columns.Add("Code");
lvCriteriaList.View = View.Details;
lvCriteriaList.CheckBoxes = true;
ListViewItem lvitem;
foreach (Criteria criteria in criterialist)
{
lvitem = lvCriteriaList.Items.Add(new
ListViewItem(criteria.Value));
lvitem.SubItems.Add(criteria.Key);
}
int scrollbarWidth = SystemInformation.VerticalScrollBarWidth;
int borderwidth = SystemInformation.BorderSize.Width;
lvCriteriaList.AutoResizeColumn(0,
ColumnHeaderAutoResizeStyle.ColumnContent);
lvCriteriaList.AutoResizeColumn(1,
ColumnHeaderAutoResizeStyle.HeaderSize);
lvCriteriaList.ClientSize = new
Size(lvCriteriaList.Columns[0].Width
+
lvCriteriaList.Columns[1].Width
+ scrollbarWidth +
(borderwidth * 2), lvCriteriaList.ClientSize.Height);
}
so input arg is List<Criteria >
Criteria has two props, Key and Value
the other listview gets input arg of StockListCollection : List<Stock>
Stock has two props Name and Ticker
so the column headers have to be different
and the object types are different
and the property names are different
and one input is List<object> and the other is a class that derives from
List<object>
i'm not seeing an easy way to get away without two separate routines,
even though they are very similar in the rest of the function
i could factor out the resize code into a function but the filling part i'm
not sure?
thoughts?
thanks
mark