2017-02-15 89 views
-4

我想顯示的消息「真」當我的DataGridView檢查複選框,但它始終顯示「假」即時尋找解決方案,這是我的代碼複選框總是返回False vb.net

Try 
     'opening the connection 
     con.Open() 
      If row.Cells(15).FormattedValue = False Then 
       'store your delete query to a variable(sql) 
       sql = "DELETE FROM terres WHERE id = '" _ 
          & CStr(row.Cells(3).FormattedValue) & "'" 
       MsgBox(row.Cells(3).FormattedValue) 
       'Set your MySQL COMMANDS 
       With cmd 
        .Connection = con 
        .CommandText = sql 
       End With 
       'Execute the Data 
       result = cmd.ExecuteNonQuery 
      End If 
     Next 
     'the condition is, if the result is equals to zero 
     'then the message will appear and says "No Deleted Record." 
     'and if not the message will appear and says "The Record(s) has been deleted.." 
     If result = 0 Then 
      MsgBox("No Deleted Record.") 
     Else 
      MsgBox("The Record(s) has been deleted.") 
     End If 
    Catch ex As Exception 
     MsgBox(ex.Message) 
    End Try 
    'Close the connection 
    con.Close() 
+1

這看起來不像C#。你爲什麼要這樣標記?你的代碼中的複選框在哪裏?它的價值在哪裏?在調試器中看到的值是什麼* –

+0

您可以發佈datagridview的標記嗎? –

+0

我怎麼能做到即時通訊使用vb 2008 @Rickjames –

回答

0

建築當你的數據表/ DataGridView中嘗試這樣的複選框列:

dtdgv.Columns.Add("Process", GetType(Boolean)) 
'More columns etc. 
'Seriously look at table adapters and 
'make SURE they wont work for your application 
'Fill dtdgv 
DataGridView1.DataSource = dtdgv 
DataGridView1.Refresh() 

然後確定何時無論是檢查還是不是這種效果:

For Each row As DataGridViewRow In DataGridView1.Rows 
    If row.Cells("Process").Value = True Then 
     'Stuff 
    End If  
Next 

你在找什麼?