sql - How to Disable DataGridView from automatically reordering columns when bound to dataset table -
i have datagridview , binding dataset object created visual studio designer. simple example: query of sql database returns columns in order : id, name, grade - fine, if query manually , return , bind no problems columns show in order returned query. required use dataset object. when datagridview bound table inside dataset (even though table columns in right order ) datagridview decides on own reorder columns!! aaargh!!
how can prevent ugly behavior ?
i not looking @ naming columns , setting ordinal positions posted here:
disable datagridview automatic ordering vb.net
that 'answer' not prevent behavior forces known column names[hard coding] , setting ordinals , datgridviews.
code example:
dim dt appdataset.booksdatatable = new appdataset.booksdatatable bookstableadapter.fillbyrecipeid(dt, id) ' checks particular field , uses drop down instead. ' can exclude behaviour same. dgvexample.autogeneratecolumns = false if dgvexample.columns.count < 1 createdatagridcolumns(dt) end if dgvexample.datasource = nothing dgvexample.datasource = bsbooks
Comments
Post a Comment