简体   繁体   中英

Datagridview Sorting with manually added columns

I have a datagridview control bound to a MySQL database column.

While loading the table to datagridview, i am adding one Column and 8 rows to the datagridview. Values to these manually added coluns and rows are also programitically added. All is working fine except the sorting. When i click on any of column header, datagridview sorts according to the bound table and the manually added column becomes blank.

I want a method to sort the datagridview even if it has a manually added column into it.

Please help....

Add the columns and the 8 rows to the table, not the gridview, and do databind after that.

Dim dt as System.Data.DataTable = fnGetData()
dt.Columns.Add("new column", GetType(String))
'' for 1 to 8
Dim dr as System.Data.DataRow = dt.NewRow()
'' Fill values
'' dr("new column") = "Some Value"
dt.Rows.Add(dr) 
GridView1.Databind()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM