vb.net - add column in datagridview -


i use vb.net excel

i have buttom "get name of column worksheet" combobox

this code of button:

private sub button7_click(byval sender system.object, byval e system.eventargs) handles button7.click     dim excols new dictionary(of integer, string)     form2.xlworksheet = ctype(form2.xlworkbook.sheets(form2.combobox1.text), excel.worksheet)     form2.xlworksheet.activate()      form2.xlworksheet         dim lastcol integer = form2.xlworksheet.cells(1,         form2.xlworksheet.columns.count).end(xldirection.xltoleft).column         x integer = 2 lastcol             excols.add(x, form2.xlworksheet.cells(1, x).value.tostring)         next         combobox2.datasource = new bindingsource(excols, nothing)         combobox2.valuemember = "key"         combobox2.displaymember = "value"         addhandler combobox2.selectedindexchanged, addressof            combobox2_selectedindexchanged     end end sub 

this code of combobox:

private sub combobox2_selectedindexchanged(byval sender system.object, byval e system.eventargs)     form2.xlworksheet = ctype(form2.xlworkbook.sheets(form2.combobox1.text), excel.worksheet)     form2.xlworksheet.activate()     form2.xlapp.visible = true     dim key string =               cstr(directcast(combobox2.selecteditem, keyvaluepair(of integer, string)).key)     dim value string =                  directcast(combobox2.selecteditem, keyvaluepair(of integer, string)).value     dim doessheetexists boolean = false     each xs in form2.xlapp.sheets         if xs.name = value             doessheetexists = true     next      if doessheetexists = true         msgbox("sheet exists", ctype(messageboxicon.error, msgboxstyle))     else         form2.xlworksheet             dim lastrow integer = form2.xlworksheet.cells.rows.end(xldirection.xldown).row             dim colletter string = columnindextocolumnletter(cint(key))             exws2 = directcast(form2.xlworkbook.sheets.add, microsoft.office.interop.excel.worksheet)             exws2.name = value             form2.xlworksheet.range("a1:a" & lastrow.tostring).copy(exws2.range("a1"))             form2.xlworksheet.range(colletter & "1:" & colletter & lastrow.tostring).copy(exws2.range("b1"))             exws2.range("a1").font.color = system.drawing.colortranslator.toole(system.drawing.color.blue)             exws2.range("b1").font.color = system.drawing.colortranslator.toole(system.drawing.color.blue)             exws2.range("a1").interior.colorindex = 8             exws2.range("b1").interior.colorindex = 8             exws2.range("a2:a" & lastrow.tostring).interior.colorindex = 20             exws2.range("a1:a" & lastrow.tostring).horizontalalignment =       -4108              exws2.range("b1:b" & lastrow.tostring).horizontalalignment = -4108             exws2.range("a1").font.name = "times new roman"             exws2.range("b1").font.name = "times new roman"             exws2.range("b1").font.fontstyle = "gras"             exws2.range("a1").font.fontstyle = "gras"         end     end if end sub 

what want add every time when select column , added datagridview

this column want add datagridview

help me please


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -