vb.net - DataGridView - Column Header Change Weirdness -


so have form in load event add dynamic number of tabpages , datagridviews (dgv) - 1 dgv per tabpage. want handle events these dgvs, add handlers. code in load that:

'add tab page , corresponding grid each table in data set = 0 bindata.binnedtables.tables.count - 1     dim tabpage c1.win.c1command.c1dockingtabpage = new c1.win.c1command.c1dockingtabpage     tabpage.text = bindata.binnedtables.tables(i).tablename     tabcontent.tabpages.add(tabpage)      dgvdata = new datagridview     addhandler dgvdata.databindingcomplete, addressof dgvdata_created     dgvdata         .dock = dockstyle.fill         .allowusertoordercolumns = false         .allowusertoaddrows = false         .allowusertodeleterows = false         .datasource = bindata.binnedtables.tables(i)         .columns.add("total", "total")         .columns("total").readonly = true     end      tabpage.controls.add(dgvdata)      'these following lines have go after dgvdata added tabpage because otherwise don't work     dgvdata.autoresizecolumnheadersheight()      each col datagridviewcolumn in dgvdata.columns         col.sortmode = datagridviewcolumnsortmode.notsortable         col.valuetype = gettype(integer)     next      addhandler dgvdata.rowpostpaint, addressof mydgv_rowpostpaint      addhandler dgvdata.keydown, addressof dgvdata_keydown     addhandler dgvdata.cellvaluechanged, addressof dgvdata_cellchanged     addhandler dgvdata.cellendedit, addressof dgvdata_celledit     addhandler dgvdata.cellvalidating, addressof dgvdata_cellvalidating      addhandler tabpage.textchanged, addressof tabpage_textchanged     addhandler dgvdata.columnheadermousedoubleclick, addressof dgvdata_columnheadermousedoubleclick     addhandler dgvdata.columnheadercellchanged, addressof dgvdata_columnheadertextchanged  next   'datatable in bindata.binnedtables.tables 

i use columnheadermousedoubleclick event allow user change text in column header. want update column name corresponding column in data source, in sync. have in columnheadermousedoubleclick:

dim renamecol new dlgnewcol renamecol.lblinsertcol.text = "rename column"  if renamecol.showdialog() = system.windows.forms.dialogresult.ok     dim thisgrid datagridview = directcast(sender, datagridview)     dim thiscol datagridviewcolumn = thisgrid.columns(e.columnindex)      thiscol.headertext = renamecol.txtcolname.text      'the index of tabpage corresponds index of table in data source     bindata.binnedtables.tables(tabcontent.selectedindex).columns(e.columnindex - 1).columnname = thiscol.headertext  end if   'if dialog result ok 

what happens, though, works whatever reason column header changed gets moved end of grid, plus other properties reset.

if comment out line update column name of table data source dgv, don't have issue column properties getting reset. however, source's column name not updated, out of sync. having table data source not automatically update column names actual data.

i figured i'd use columnheadercellchanged event change these properties supposed be, because i'd expect code above fire that....but doesn't.

so guess questions are: why changing column name of data source have effect (changing properties of dgv's column)?, why columnheadercellchanged event not firing?, , there other way can manage change both dgv column's header , data source's column name, plus have column's other properties remain (or put back)?

thank you!

looks autogeneratecolumns on. you'll need turn off , manual add columns.


Comments