I searched a lot but couldn't find any solution. I am probably using the wrong keywords. I have a class which is basically an extended version of ListView control.
I defined some custom attributes for my customized ListView, such as FileName, OrderType etc, and they work fine.
I also want to pass an array to my class which includes ColumnNames to populate the data within class.
In MyListView
Class
public class ColumnNames : Attribute
{
public string[] Values { get; set; }
public ColumnNames(params string[] values)
{
this.Values = values;
}
}
[ColumnNames("a1","a2","a3","a4","a5","a6","a7","a8","a9")]
public MyListView() {
for (int i = 0; i < 7; i++)
this.Columns.Add(this.ColumnNames[i]);
}
In Form1
Class
MyListView lstv = new MyListView();
lstv.ColumnNames[0] = "hede1";
lstv.ColumnNames[1] = "hede2";
lstv.ColumnNames[2] = "hede3";
EDIT : I simply couldn't achieve what I wanted. Could you show me a working example of this?
I use this listview to display information taken from a database. (I use ListView instead of DataGrid) I want to pass the column names to this class which will be used both for SQL query "SELECT xxxxx, yyyyy, zzzz FROM table;" and column names this.columns.add("xxxxx"); this.columns.add("yyyyy"); this.columns.add("zzzzz");