473,322 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

filling textbox from datagrid

cj
This should be easy. I have a datagrid filled with data and when I
click on a cell I want that data displayed in a text box. How do I do
this? Thanks. P.S. this is a 2005 windows app.
Nov 12 '07 #1
5 1985
On Nov 12, 3:57 pm, cj <c...@nospam.nospamwrote:
This should be easy. I have a datagrid filled with data and when I
click on a cell I want that data displayed in a text box. How do I do
this? Thanks. P.S. this is a 2005 windows app.

textbox1.text = datagridview1(0,
processgrid.CurrentCell.RowIndex).Value

Nov 12 '07 #2
cj
What's processgrid?

Peter Forman wrote:
On Nov 12, 3:57 pm, cj <c...@nospam.nospamwrote:
>This should be easy. I have a datagrid filled with data and when I
click on a cell I want that data displayed in a text box. How do I do
this? Thanks. P.S. this is a 2005 windows app.


textbox1.text = datagridview1(0,
processgrid.CurrentCell.RowIndex).Value
Nov 12 '07 #3
Hi Cj,

If you're using a DataGrid control on your form, you can handle the
CurrentCellChanged event of the DataGrid control and get the value in the
current cell. The following is a sample:

Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.CurrentCellChanged
If Not (Me.DataGrid1(Me.DataGrid1.CurrentCell) Is Nothing) Then
Me.TextBox1.Text =
Me.DataGrid1(Me.DataGrid1.CurrentCell).ToString()
End If
End Sub

If you're using a DataGridView control on your form, you can also handle
the CurrentCellChanged event of the DataGridView control and then get the
value of the current cell. The following is a sample:

Private Sub DataGridView1_CurrentCellChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles DataGridView1.CurrentCellChanged
If Not (Me.DataGridView1.CurrentCell.Value Is Nothing) Then
Me.TextBox1.Text = Me.DataGridView1.CurrentCell.Value.ToString()
End If
End Sub

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 13 '07 #4
cj
Hi linda,

Your answer did lead me to my solution. I'm not sure why you used
CurrentCellChanged event as I didn't want to change any data in this
case but you did point me in the right direction. Here is what I did.

Private Sub DataGridView1_CellContentClick(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellContentClick
TextBox1.Text = DataGridView1.CurrentCell.Value
End Sub
Linda Liu[MSFT] wrote:
Hi Cj,

If you're using a DataGrid control on your form, you can handle the
CurrentCellChanged event of the DataGrid control and get the value in the
current cell. The following is a sample:

Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.CurrentCellChanged
If Not (Me.DataGrid1(Me.DataGrid1.CurrentCell) Is Nothing) Then
Me.TextBox1.Text =
Me.DataGrid1(Me.DataGrid1.CurrentCell).ToString()
End If
End Sub

If you're using a DataGridView control on your form, you can also handle
the CurrentCellChanged event of the DataGridView control and then get the
value of the current cell. The following is a sample:

Private Sub DataGridView1_CurrentCellChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles DataGridView1.CurrentCellChanged
If Not (Me.DataGridView1.CurrentCell.Value Is Nothing) Then
Me.TextBox1.Text = Me.DataGridView1.CurrentCell.Value.ToString()
End If
End Sub

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 15 '07 #5
Hi Cj,

Thank you for your reply!

Glad to hear that your problem is solved.

I just took an example by using the CurrentCellChanged event of the
DataGridView in my sample code.

If the CellContentClick event is more propriate to your pratice, you can
use it of course.

If you have any other questions in the future, please don't hesitate to
contact us. It's always our pleasure to be of assistance!

Sincerely,
Linda Liu
Microsoft Online Community Support

Nov 16 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrea Trevisan | last post by:
That's a revival of a known thing I suppose.I hope it's useful. My problem was: I want to have a DataGrid with two Template columns: first with TextBox,second with Button.I want to fire an event...
3
by: Omar Llanos | last post by:
I have Form1 and Form2 (which is inherited from Form1), and I created a button in Form2 that will fill up a textbox in Form1. What code would do that? I tried the simplest way: //from child...
1
by: Krzysztof Karnicki | last post by:
I have such a problem… I have create my custom DataGridColumn inheriting from System.Windows.Forms.DataGridColumnStyle on using it on DataGrid, to show rows painted by me self. Because dates ...
1
by: thegame | last post by:
Filling One DataGrid Based on Selection from Another DataGrid - Both in Separate User Controls Hello, I have an interesting dilemma. I have an ASPX page with two user controls (two ASCXs). ...
7
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
2
by: Saket Mundra | last post by:
I have a Datagrid in which i want to dispaly only those rows that match the text specified by user in the text box.How do i do that ? How do i refresh the data in the Datagrid everytime the text is...
0
by: Nigpig | last post by:
Hi I have a datagrid with button columns that about 1 in 4 times fails to completely fill the columns. When this happens the rest of the page is not completed but terminates rendering after the...
0
by: nigel | last post by:
Hi I have a datagrid with button columns that about 1 in 4 times fails to completely fill the columns. When this happens the rest of the page is not completed but terminates rendering after the...
1
by: WayneM | last post by:
I have compact framework app that I was trying to test out on a windows form, but I cannot get past the very first step of simply filling a DataGrid from a DataSet. My code is Dim sqlStmt As...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.