I’m extending my question here Dynamically Creating GridView and trying a different approch as suggested, but im stuck again.
I have a table that handles my names and order of key values.
KeyNames:
ID Int primary key
KeyName1 varchar(20)
KeyOrder int
KeyName2 varchar(20)
KeyOrder int
...
KeyNameN varchar(20)
KeyOrder int
These Keys represent the Name and Order of another table to be displayed in a gridview. ie:
DocumentTable:
ID int primary key
PDF_Folder varchar(30)
Key1value varchar(100)
Key2value varchar(100)
..
KeyNvalue varchar(100)
So in my gridview the user can decide the column names of the Keys and the value (I might want to called Key1 “description” order 1 and Key2 “Names Mentioned” and order 2.
if Order < 0 then it will not be displayed in the gridview.
Im stuck on how I will create a gridview to display each columns for KeyNValue with the colmn name KeyNameN and the order of KeyOrderN..
You will use the DisplayIndex property of the DataGridViewColumn to set the Order.
You will use the HeaderText property to set the name.
I see you have no rows, so the grid will have just one row with many columns.
So, assuming you have a grid named MyGrid, each column is in a class named MyEntityRecord, you have put all columns in a list and you want to display the data after the user clicks on a button, here is a sample code to be called from the Click Event.
If I understood correctly, this should do what you wanted.