Link to home
Start Free TrialLog in
Avatar of searchsanjaysharma
searchsanjaysharma

asked on

How to freeze the datagridview to return the current cell value only.

I have the following code, When i click on any cell, of the grid of any column, it return the value of that particular cell in admissionhead.txtauin.Text textbox.

But i want it should be like - any cell of that particular row is clicked, only uin field should be assigned to admissionhead.txtauin.Text

Presently it returns the value of any cell tht is clicked.


Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        If e.ColumnIndex > -1 AndAlso e.RowIndex > -1 AndAlso TypeOf sender.CurrentCell Is DataGridViewTextBoxCell Then 'AndAlso TypeOf sender.CurrentCell Is DataGridViewTextBoxCell
            admissionhead.txtauin.Text = sender.CurrentCell.EditedFormattedValue().ToString().Trim()
            Me.Hide()
        End If
    End Sub

    Private Sub DataGridView1_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentDoubleClick
        If e.ColumnIndex > -1 AndAlso e.RowIndex > -1 AndAlso TypeOf sender.CurrentCell Is DataGridViewTextBoxCell Then 'AndAlso TypeOf sender.CurrentCell Is DataGridViewTextBoxCell
            admissionhead.txtauin.Text = sender.CurrentCell.EditedFormattedValue().ToString().Trim()
            Me.Hide()
        End If
    End Sub

    Private Sub DataGridView1_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
        If e.ColumnIndex > -1 AndAlso e.RowIndex > -1 AndAlso TypeOf sender.CurrentCell Is DataGridViewTextBoxCell Then 'AndAlso TypeOf sender.CurrentCell Is DataGridViewTextBoxCell
            admissionhead.txtauin.Text = sender.CurrentCell.EditedFormattedValue().ToString().Trim()
            Me.Hide()
        End If
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of searchsanjaysharma
searchsanjaysharma

ASKER

The column index is 1, but after implementing its returning False

admissionhead.txtauin.Text = admissionhead.txtauin.Text = CType(sender, DataGridView).Item(1, e.RowIndex).Value
False as in the word false? Apply the ToString to the value
Yes False is coming in the textbox. To string is also returning false
Try this in the DataGridView's CellContentClick event.
admissionhead.txtauin.Text = CType(sender, DataGridView).Item(1, e.RowIndex).FormattedValue

Open in new window

NOT
admissionhead.txtauin.Text = admissionhead.txtauin.Text = CType(sender, DataGridView).Item(1, e.RowIndex).Value

Open in new window

The code you have will always give a Boolean result since you have two equals' signs! (and that is NOT the code I suggested before).
sorry it didnt worked out. However i applied my own logic.Thanks
You need to be honest with your remarks, and there is nothing wrong with admitting that you made an error!