c# - error in get data from access database to datagridview Vb.Net -
i have problem when click item in datagridview more information ! ok ? code :
try if (datagridview1.rows.count = 0) return textbox1.text = string.empty textbox2.text = string.empty textbox3.text = string.empty textbox4.text = string.empty dim id string = datagridview1(2, datagridview1.selectedrows(0).index).value dim dt datatable = new dbconnect().selectdata(string.format("select items.clientname, items.clientaddress, items.clientphone, items.clientcredit, items.clientlastpay items items.clientid = {0}", id)) textbox1.text = dt.rows(0)(0).tostring textbox2.text = dt.rows(0)(1).tostring textbox3.text = dt.rows(0)(2).tostring textbox4.text = dt.rows(0)(3).tostring dt.dispose() dt = nothing catch ex exception messagebox.show(ex.message) end try
by debugging error in line :
dim id string = datagridview1(2, datagridview1.selectedrows(0).index).value.tostring
thats full source code http://up.dev-point.com/download279606.html
you trying access datagridview array, when need specify you're looking in rows , columns. instead of
datagridview1(2, datagridview1.selectedrows(0).index).value
you can write
datagridview1.columns(2).cells(datagridview1.selectedrows(0).index).value
however, relying on selectedrows not best way it. if user accidentally selected few rows , clicked bottom one?
assuming code in cellclick handler
(sender object, e datagridviewcelleventargs)
you should use datagridviewcelleventargs tell row you're on instead of relying on selectedrows:
dim id string = datagridview1(e.rowindex).cells(2).value
Comments
Post a Comment