Click here to Skip to main content
15,846,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi I m using data grid view with check box in search page in vb.net windows form
it is showing two extra field which I did not add even i make it false in visible
but in run time it is showing
herewith I given the coding please check & help------


VB
Private Sub frmUploadCustomerFiles_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.Location = New Point(Me.MdiParent.ClientSize.Width / 2 - Me.Width / 2, Me.MdiParent.ClientSize.Height / 2 - Me.Height / 2)
       dgvSearch.Columns.Add("MDS_RecNum", "Customer_ID") 'coz if Chk column added first then first row is not selecting while doing check...
       Dim colToCheck As New DataGridViewCheckBoxColumn 'Check box Column
       dgvSearch.Columns.Add(colToCheck)

       Dim view As New DataGridViewLinkColumn 'this for viewing File
       dgvSearch.Columns.Add(view)
       chk = New CheckBox
       chk.Size = New Size(16, 16)
       chk.BackColor = Color.DarkGreen
       AddHandler (chk.CheckedChanged), AddressOf chk_CheckedChanged
       chk.Location = New System.Drawing.Point(7, 10)

       dgvSearch.Controls.Add(chk)

       FillState()
   End Sub

---------------------------------------------------------------------------------------------------------------

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        Try

            LocationSearchByIdOrAddress()
        Catch ex As Exception
            DisplayError(ex)
            LogApplicationsErrors(ex, System.Reflection.MethodBase.GetCurrentMethod().Name, Me.Name)
        End Try
    End Sub

----------------------------------------------------------------------------------------------------------------

 Public Sub LocationSearchByIdOrAddress()
        Try
            If txtSearchKey.Text.Trim = "" And cboState.Text.Trim = "" And txtCity.Text.Trim = "" Then
                MsgBox("Please enter atleast one data to search", MsgBoxStyle.Information, "Enter")
                txtSearchKey.Select()
                Exit Sub
            End If
            Dim sqlstr As New StringBuilder
            Dim dsCusmas As New DataSet
            dgvSearch.Visible = False
            'sqlstr.Append("Exec ESP_SearchLocationMaster ") 'Windows Application Location Master
            'Web application 
            'sqlstr.Append("ESP_getRecordLocationMaster ")
            sqlstr.Append("ESP_SearchCustomerUpLoadFile ")
            sqlstr.Append(PrepareString(txtCity.Text.Trim) & COMMA)
            sqlstr.Append(PrepareString(cboState.Text.Trim) & COMMA)
            sqlstr.Append(PrepareString(txtSearchKey.Text.Trim) & COMMA)
            sqlstr.Append(PrepareString(1))
            Application.DoEvents()

            lblmessage.Text = "Searching please wait........"
            Application.DoEvents()
            dsCusmas = getSQLDataSet(sqlstr.ToString)
            dgvSearch.DataSource = dsCusmas.Tables(1)
            If dgvSearch.RowCount = 0 Then
                lblmessage.Text = "There are no locations found under this search criteria"
                dgvSearch.Visible = False
                grboxSelectFile.Visible = False
                Exit Sub
            End If
            grboxSelectFile.Visible = True
            lblmessage.Text = "Records found :" & dgvSearch.RowCount
            dgvSearch.Visible = True
            dgvSearch.DefaultCellStyle.Font = New Font("Verdana", 8, FontStyle.Regular)
            dgvSearch.AlternatingRowsDefaultCellStyle.Font = New Font("Verdana", 8, FontStyle.Regular)
            dgvSearch.EnableHeadersVisualStyles = False
            dgvSearch.ColumnHeadersDefaultCellStyle.BackColor = Color.DarkGreen
            dgvSearch.ColumnHeadersDefaultCellStyle.SelectionBackColor = Color.DarkGreen
            dgvSearch.ColumnHeadersDefaultCellStyle.Font = New Font("Verdana", 8, FontStyle.Bold)




            dgvSearch.Columns("Customer_ID").DisplayIndex = 1
            dgvSearch.Columns("Customer_ID").ReadOnly = True
            dgvSearch.Columns("Customer_ID").HeaderText = "Customer Id"
            dgvSearch.Columns("Customer_ID").Visible = True

            dgvSearch.Columns("Customer_Name").Width = 170
            dgvSearch.Columns("Customer_Name").DisplayIndex = 2
            dgvSearch.Columns("Customer_Name").ReadOnly = True
            dgvSearch.Columns("Customer_Name").HeaderText = "Cuastomer Name"

            dgvSearch.Columns("Address1").Width = 170
            dgvSearch.Columns("Address1").DisplayIndex = 3
            dgvSearch.Columns("Address1").ReadOnly = True
            dgvSearch.Columns("Address1").HeaderText = "Address1"

            dgvSearch.Columns("City").Width = 90
            dgvSearch.Columns("City").DisplayIndex = 4
            dgvSearch.Columns("City").ReadOnly = True
            dgvSearch.Columns("City").HeaderText = "City"

            dgvSearch.Columns("State").Width = 45
            dgvSearch.Columns("State").DisplayIndex = 5
            dgvSearch.Columns("State").ReadOnly = True
            dgvSearch.Columns("State").HeaderText = "State"

            dgvSearch.Columns("Zip").Width = 90
            dgvSearch.Columns("Zip").DisplayIndex = 6
            dgvSearch.Columns("Zip").ReadOnly = True
            dgvSearch.Columns("Zip").HeaderText = "Zip"

            dgvSearch.Columns("Phone").Width = 100
            dgvSearch.Columns("Phone").DisplayIndex = 7
            dgvSearch.Columns("Phone").ReadOnly = True
            dgvSearch.Columns("Phone").HeaderText = "Phone"

            dgvSearch.Columns("CustAuthFileName").Width = 130
            dgvSearch.Columns("CustAuthFileName").DisplayIndex = 8
            dgvSearch.Columns("CustAuthFileName").ReadOnly = True
            dgvSearch.Columns("CustAuthFileName").HeaderText = "FileName"
            dgvSearch.Columns("CustAuthFileName").Visible = True

            dgvSearch.Columns("ID").Visible = False
            dgvSearch.Columns("MDS_RECNUM").Visible = False

            dgvSearch.Columns("Fax").Visible = False
            dgvSearch.Columns("Address2").Visible = False


            'dgvSearch.Columns("Authorization_Req").Visible = False
            'dgvSearch.Columns("LocationAlpha").Visible = False

            'dgvSearch.Columns(0).Width = 0
            'dgvSearch.Columns(0).HeaderText = "Edit"
            dgvSearch.Columns(0).DisplayIndex = 1
            'dgvSearch.Columns(0).ReadOnly = True


            dgvSearch.Columns(1).Width = 25
            dgvSearch.Columns(1).DisplayIndex = 0
            dgvSearch.Columns(1).HeaderText = ""
            dgvSearch.Columns(0).ReadOnly = True



            'Dim row As DataGridViewRow

            'For Each row In dgvSearch.Rows
            '    row.Cells(0).Value = row.Cells(3).Value

            '    Dim lnk As New DataGridViewLinkColumn
            '    lnk = row.Cells(8).OwningColumn()
            '    lnk.HeaderText = "Existing Files"
            '    If row.Cells("CustAuthFileName").Value.ToString() <> "" Then  'If file exist giving the link view
            '        row.Cells(11).Value = "View"
            '    Else
            '        row.Cells(11).Value = ""
            '    End If
            'Next


        Catch ex As Exception
            DisplayError(ex)
            LogApplicationsErrors(ex, System.Reflection.MethodBase.GetCurrentMethod().Name, Me.Name)
        End Try
    End Sub
Posted
Updated 26-Jan-11 20:19pm
v2
Comments
m@dhu 27-Jan-11 1:20am    
Edited for code block.
IndrajitDasgupat 27-Jan-11 1:28am    
sorry I didn't understand plz describe
Nithin Sundar 27-Jan-11 1:29am    
He meant to say that the given code in your question is now more readable than before. That's what the code block does.
Abhinav S 27-Jan-11 1:32am    
Which two fields?
IndrajitDasgupat 27-Jan-11 1:32am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900