Home » C++ ProgrammingRSS

how to show data in textbox when mouse click on any cell grid in vb.net with text file?

hi,

how to show data in textbox  when mouse click on any cell grid in vb.net with text file?

thanks

 

6 Answers Found

 

Answer 1

I assume you are reading a textfile into a datagridview ???

I would suggest reading the textfile into an in-memory datatable, and set the datagridview datasource to the table

once the data  is in the DataGridView, you can use the CellClick event to get the value from that cell

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString
  End Sub
 

Answer 2

it don't work because i fetch data  in grid  from notepad file  but i want when i click  any cell  of grid data show  in textbox?
 

Answer 3

or there is no cellclick event
 

Answer 4

Hello,

believe me there is!
if you want to become an expert and not want a be an expert this task should be easy for you

just open a new project,
add a textbox  and
a dgv
copy paste the code from jwavila

and voila....

 

With kind regards,

 

rocky

 

Answer 5

you need to do 2 things:

1. learn about the Properties and Methods for Controls in Windows Forms

2. before you do #1 above, you need to learn how to use the Visual Studio IDE, including how to get to the Methods and Properties available for each Control

to show  how it works, create a new Windows Forms app and add a DataGridview and a TextBox from the Toolbox to the Form

paste this code in the code editor between the Public Class Form1 and End Class lines

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'add Columns to DGV
    DataGridView1.Columns.Add("Value1", "Value1")
    DataGridView1.Columns.Add("Value2", "Value2")
    'instantiate Random Class
    Dim rndm As New Random
    'populate DGV with data
    For i As Integer = 1 To 10
      DataGridView1.Rows.Add("Row " & i.ToString, rndm.Next(0, 31))
    Next
  End Sub

  Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
    'display data  in clicked cell  in TextBox
    TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString
  End Sub
 

Answer 6

Hello want to become expert in .net,
Thanks for your post.
If you think the answer provides no help, please Unpropose As Answer, not abusive. Thanks.
If you have any problems, please feel free to follow up.
Best regards,
Liliane
abusive
 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter