Tuesday, 8 December 2015

Adding CheckBox to DataGridView in VB.NET

The DataGridView control uses several column types to display its information and enable users to modify or add information. The DataGridView control provides TextBox, CheckBox, Image, Button, ComboBox and Link columns with the corresponding cell types.
The following vb.net program shows how to add a CheckBox in Cell of a DataGridView control and set the third row checkbox value as true. If you want to respond immediately when users click a check box cell, you can handle the CellClick event, but this event occurs before the cell value is updated.

Example:

Imports System.Data.SqlClient
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        DataGridView1.ColumnCount = 3
        DataGridView1.Columns(0).Name = "Product ID"
        DataGridView1.Columns(1).Name = "Product Name"
        DataGridView1.Columns(2).Name = "Product_Price"

        Dim row As String() = New String() {"1", "Product 1", "1000"}
        DataGridView1.Rows.Add(row)
        row = New String() {"2", "Product 2", "2000"}
        DataGridView1.Rows.Add(row)
        row = New String() {"3", "Product 3", "3000"}
        DataGridView1.Rows.Add(row)
        row = New String() {"4", "Product 4", "4000"}
        DataGridView1.Rows.Add(row)

        Dim chk As New DataGridViewCheckBoxColumn()
        DataGridView1.Columns.Add(chk)
        chk.HeaderText = "Check Data"
        chk.Name = "chk"
        DataGridView1.Rows(2).Cells(3).Value = True

    End Sub
End Class

Friday, 4 December 2015

Cannot always wait for the Perfect time,

You Cannot always wait for the Perfect time,
Sometime you must dare to jump.

Life is Not always Perfect


Life is not Perfect.. There is always a Possibility for a problem, the problem is not the end,
 But it's the beginning of different life

TeamWork

Teamwork Is More Important Than Independent Work

Think Bigger

THINK BIGGER MAKE MORE

Success

Your Role may be thankless, but if you're willing to give it your all,
you just might bring success to those who outlast you

Global Connection Code in Vb.net

Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms

Module [Global]

''---------------------------------------------------------------------------------------------------- 
    Public Const scon As String = "Data Source=servername8;Initial Catalog=databasename;" & _
                                                           "Persist Security Info=True;User ID=SA;Password=Welcome"

    Public struser As String = "ADMIN"
    Public ssql As String
    Public strtem As String
    Public inttem As Integer
    Public blntemp As Boolean

    Public dttable As DataTable
    Public dtset As New DataSet()
    Public dataAdapt As New SqlDataAdapter()

    Public sqlConnection As SqlConnection = New SqlConnection(scon)
    Public sqlcmd As SqlCommand
''----------------------------------------------------------------------------------------------------
    Public Function dsdttable(ByVal sql As String)
        Try
            dttable = Nothing
            Using conn As New SqlConnection(scon)
                Using comm As New SqlCommand()
                    With comm
                        .Connection = conn
                        .CommandType = CommandType.Text
                        .CommandText = sql

                        Try
                            conn.Open()
                            dataAdapt.SelectCommand = comm
                            dtset.Dispose()
                            dtset.Tables.Clear()
                            dataAdapt.Fill(dtset)
                            dataAdapt.Dispose()
                            comm.Dispose()
                            conn.Close()
                            dttable = dtset.Tables(0)
                            dtset.Dispose()
                            Return dttable


                        Catch ex As Exception
                            MessageBox.Show(ex.Message.ToString(), "Error Message")
                        End Try
                    End With
                End Using
            End Using

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Function
''----------------------------------------------------------------------------------------------------
    Public Function ExecuteSql(ByVal sql As String) As Boolean
        Try
               Using conn As New SqlConnection(scon)
                Using comm As New SqlCommand()
                    With comm
                        .Connection = conn
                        .CommandType = CommandType.Text
                        .CommandText = sql
                    End With
                    Try
                        conn.Open()
                        comm.ExecuteNonQuery()
                        conn.Close()
                        Return True
                    Catch ex As Exception
                        MessageBox.Show(ex.Message.ToString(), "Error Message")
                    End Try
                End Using
            End Using
        Catch ex As Exception
            MsgBox(ex.ToString)
            Return False
        End Try
    End Function
''----------------------------------------------------------------------------------------------------
  Public Function cConOpen() As Boolean
        Try
            If ConnectionState.Open = True Then
                sqlConnection.Close()
                sqlConnection.Open()
                Return True
             Else
                sqlConnection.Open()
                Return True
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Function
''----------------------------------------------------------------------------------------------------
End Module