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_CellContentC lick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataG ridViewCel lEventArgs ) Handles DataGridView1.CellContentC lick
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.EditedF ormattedVa lue().ToSt ring().Tri m()
Me.Hide()
End If
End Sub
Private Sub DataGridView1_CellContentD oubleClick (ByVal sender As Object, ByVal e As System.Windows.Forms.DataG ridViewCel lEventArgs ) Handles DataGridView1.CellContentD oubleClick
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.EditedF ormattedVa lue().ToSt ring().Tri m()
Me.Hide()
End If
End Sub
Private Sub DataGridView1_CellMouseDou bleClick(B yVal sender As Object, ByVal e As System.Windows.Forms.DataG ridViewCel lMouseEven tArgs) Handles DataGridView1.CellMouseDou bleClick
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.EditedF ormattedVa lue().ToSt ring().Tri m()
Me.Hide()
End If
End Sub
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_CellContentC
If e.ColumnIndex > -1 AndAlso e.RowIndex > -1 AndAlso TypeOf sender.CurrentCell Is DataGridViewTextBoxCell Then 'AndAlso TypeOf sender.CurrentCell Is DataGridViewTextBoxCell
admissionhead.txtauin.Text
Me.Hide()
End If
End Sub
Private Sub DataGridView1_CellContentD
If e.ColumnIndex > -1 AndAlso e.RowIndex > -1 AndAlso TypeOf sender.CurrentCell Is DataGridViewTextBoxCell Then 'AndAlso TypeOf sender.CurrentCell Is DataGridViewTextBoxCell
admissionhead.txtauin.Text
Me.Hide()
End If
End Sub
Private Sub DataGridView1_CellMouseDou
If e.ColumnIndex > -1 AndAlso e.RowIndex > -1 AndAlso TypeOf sender.CurrentCell Is DataGridViewTextBoxCell Then 'AndAlso TypeOf sender.CurrentCell Is DataGridViewTextBoxCell
admissionhead.txtauin.Text
Me.Hide()
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
False as in the word false? Apply the ToString to the value
ASKER
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
NOTadmissionhead.txtauin.Text = admissionhead.txtauin.Text = CType(sender, DataGridView).Item(1, e.RowIndex).Value
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).
ASKER
sorry it didnt worked out. However i applied my own logic.Thanks
ASKER
ok
You need to be honest with your remarks, and there is nothing wrong with admitting that you made an error!
ASKER
admissionhead.txtauin.Text