vb.net - Set DataGridViewComboBoxColumn Value Based on a Datatable -


i read several article relating setting value of combobox still couldn't come solution.

below basic example of want , in comments want do. appreciated.

  public sub form1_load(sender system.object, e system.eventargs) handles mybase.load     dim dt new datatable     dt.columns.add("id")     dt.columns.add("name")     dt.columns.add("value")     dt.columns(0).autoincrement = true      integer = 0 20         dim r datarow = dt.newrow         r("name") = "test" & date.now & "" &         if = 2 or = 5 or = 6 or = 8 or = 10             r("value") = "yes"         else             r("value") = "no"         end if         dt.rows.add(r)         datagridview1.datasource = dt     next      datagridview1.readonly = false      dim cmb new datagridviewcomboboxcolumn()     cmb.headertext = "select data"     cmb.name = "cmb"     cmb.maxdropdownitems = 2     cmb.items.add("true")     cmb.items.add("false")     datagridview1.columns.add(cmb)      each dr datarow in dt.rows         if dr("name").tostring = "test"             'set combo box value true         else             'set combobox value false         end if     next  end sub 

you can set value setting cells.value...

 datagridview1.rows(whatrowdoyouwant).cells("cmb").value = true  

on note, set datasource datagridview, loop through datatable. if want set each row in datagridview wont work.

 each dr datarow in dt.rows     if dr("name").tostring = "test"         'set combo box value true     else         'set combobox value false     end if  next 

you need loop through each datagridviewrow in datagridview , set combobox value. example...

 integer = 0 datagridview1.rows.count - 1     if datagridview1.rows(i).cells("name").value.tostring = "test"         datagridview1.rows(i).cells("cmb").value = true      else         datagridview1.rows(i).cells("cmb").value = false     end if  next 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -