c# - Setting the selected cell on DataGridView causes a hidden exception -
c# - Setting the selected cell on DataGridView causes a hidden exception -
i have datagridview filled using oledbdataadapter. however, realized when seek set current selected row (cell) on datagridview, hidden exception occurs. have removed try-catch block exception thrown. nullreferenceexception. 1 time programme passes line, rest of lines on method ignored , form shows unusual behavior. illustration close box on form disappears.
this snipped of code when load records , seek fill datagridview:
dgvcampaigns.datasource = dscampaigns; dgvcampaigns.datamember = "campaigns"; dgvcampaigns.columns["id"].visible = false; dgvcampaigns.columns["rownum"].visible = false; if (dscampaigns.tables["campaigns"].rows != null) if (dscampaigns.tables["campaigns"].rows.count > 0) { mngselectedindex = 0; dgvcampaigns.currentcell = dgvcampaigns[0, 0]; } if (dgvcampaigns.currentcell != null) pnlmanagecampaignactivities.enabled = true; lblcurrentpage.text = mngcurrentpage.tostring(); lbltotalpages.text = mngpagescount.tostring(); lblcampaigncount.text = mngcampaigncount.tostring(); lbllastrefreshedvalue.text = datetime.now.tostring(); updatepaginationlinkvalues(); the line causes problem
dgvcampaigns.currentcell = dgvcampaigns[0, 0]; after line, rest of lines ignored , no exception thrown.
c# .net winforms datagridview nullreferenceexception
Comments
Post a Comment