none
adding check box to datagrid with condition RRS feed

  • Question

  • can some buddy help with code that will do an condition like that

    1- adding check box column to data grid

    2- make the check box's enabled for checked or un checked   

    3- when the timer run to make binding move next row the code will check if the (checkbox) in that row is selected or not and do something like an if condition 

     

    If CheckBox1.checked = True Then


                MsgBox(

    "admin")

           

    End If

    thanks

     

    Tuesday, February 21, 2017 2:16 PM

All replies

  • Hi feras29,

    >>1- adding check box column to data grid

    About your first question, I add DataGridView on form, please follow up the screenshots:

    Click Edit Column

    Click Add

    Choose CheckBox

    >>make the check box's enabled for checked or un checked, when the timer run to make binding move next row the code will check if the (checkbox) in that row is selected or not and do something like an if condition 

    I do a simple sample that you can refer to.

    Code sample:

    Public Sub New()
                    InitializeComponent()
                    BindGrid()
                    IsSelect()
    End Sub
    Private Sub BindGrid()
                    Dim ConnectionString As String = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\C#\WinFormC\WinFormC\DataTest.mdf;Integrated Security=True"
                    Dim sql As String = "select * from Test1"
                    Dim dt As New DataTable()
                    Using con As New SqlConnection(ConnectionString)
                                    Using cmd As New SqlCommand(sql, con)
                                                    cmd.CommandType = CommandType.Text
                                                    Using sda As New SqlDataAdapter(cmd)
                                                                    sda.Fill(dt)
                                                                    dataGridView1.DataSource = dt
                                                    End Using
                                    End Using
                    End Using
    End Sub
    
    Private Sub IsSelect()
                    Dim message As String = ""
                    For Each row As DataGridViewRow In dataGridView1.Rows
                                    Dim isSelect__1 As Boolean = Convert.ToBoolean(row.Cells("ColumnSelect").Value)
                                    If isSelect__1 Then
                                                    message += row.Cells("ColumnName").Value.ToString()
                                    End If
                                    MessageBox.Show(Convert.ToString("Select Value") & message)
                    Next
    End Su
    

    I also find Add CheckBox Column to DataGridView that may be helpful to you.

    Best Regards,

    Neda Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 22, 2017 2:44 AM
    Moderator
  • can you see this code

        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    
            For Each row As DataGridViewRow In DataGridView1.Rows
    
                If row.Cells(0).Value = "True" Then
    
                    StudentsfileBindingSource.Filter = "completname = '" & StudentinfoLabel1.Text & "'"
    
                    Dim request As HttpWebRequest
                    Dim response As HttpWebResponse = Nothing
                    Dim url As String
                    Dim username As String = "????"
                    Dim password As String = "?????"
                    Dim message As String = "سارع بسداد المستحق لاشتراك طفلك:" + StudentinfoLabel1.Text + " (كوكب طفولتي)"
                    url = "https://www.enjazsms.com/api/sendsms.php?" _
                             & "username=" & HttpUtility.UrlEncode(username) _
                             & "&password=" + HttpUtility.UrlEncode(password) _
                             & "&message=" + HttpUtility.UrlEncode(message) _
                             & "&numbers=" + HttpUtility.UrlEncode(ParentphoneLabel1.Text) _
                             & "&sender=ChildPlanet" _
                             & "&unicode=E" _
                             & "&return=full"
                    request = DirectCast(WebRequest.Create(url), HttpWebRequest)
                    response = DirectCast(request.GetResponse(), HttpWebResponse)
    
    
    
    
                End If
    
    
            Next
    
    
    
    
            SubscriptionsBindingSource.MoveNext()
    
            Dim intRecordCount As Integer = SubscriptionsBindingSource.Count
            If Me.SubscriptionsBindingSource.Position = intRecordCount - 1 Then
                Timer1.Enabled = False
                MsgBox("sms sended", MsgBoxStyle.Information, "admin")
            End If
    
    
    
          
        End Sub

    its take to match time and coming with error   

    Wednesday, February 22, 2017 12:42 PM
  • Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Timer1.Enabled = True
            SubscriptionsBindingSource.MoveFirst()
    
        End Sub

    that's the button code 
    Wednesday, February 22, 2017 12:44 PM
  • Hi feras29,

    Can you provide specific error information with me, so that I can try my best to help you?

    I would suggest that you can set breakpoints to debug your code line by line, find the error message. And post related error message or some screenshots. It will help us analyze and diagnose this issue more clearly.

    Best Regards,

    Neda Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, February 23, 2017 3:23 AM
    Moderator
  • Feras,

    What kind of DataGrid are you talking about. Here a sample on our website for the Windows Forms DataGrid

    http://www.vb-tips.com/DataGridBoolColumn.aspx


    Success
    Cor

    Thursday, February 23, 2017 9:34 AM