Solved

DataGridView help

Posted on 2008-10-10
10
603 Views
Last Modified: 2013-12-17
Experts,

I am new to development. I am using VS2008 and C#. I am I am trying to fill different controls and other things on my form based on the value of certain columns in the current row of a DataGridView control. For example one line of code is:
comboTech1.Text = wd_help_deskDataGridView.CurrentRow.Cells["help_tech"].Value.ToString();

My question is, what DGV event should I use to fire when a new row gets focus. I tried using RowEnter event but the CurrentRow value is not set when this event triggers. RowStateChanged also seems to have the same problem. The only event I've been somewhat successful with is RowPrePaint but this fires multiple times when the DGV populates each line and it does not seem very efficient. Is there an event I am not seeing or am I going about this wrong?

Thanks,
Chad
0
Comment
Question by:kalittaair
  • 5
  • 4
10 Comments
 
LVL 4

Expert Comment

by:jlj1527
ID: 22692332
Try SelectionChanged Event
0
 

Author Comment

by:kalittaair
ID: 22692338
Thx for the quick response. But won't that event also fire if the user changes to a different cell in the same row? I only want it to take place if the row changes.

Thanks,
Chad
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 22692388
Hi kalittaair,

Use the RowEnter event -> http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowenter.aspx

Regards,

Wayne
0
 

Author Comment

by:kalittaair
ID: 22692528
Wayne,

You'll notice my example uses the CurrentRow value. The CurrentRow value is not set on a RowEnter event. When RowEnter fires, the value of the CurrentRow is actually the row that just lost the focus, not the new one. If i use this event, how do I determine which row just got the focus?

Thanks,
Chad
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 22692937
wd_help_deskDataGridView.Rows(e.RowIndex)
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:kalittaair
ID: 22693678
I see. I use the RowEnter event but rather then use the CurrentRow value to find the new row I use e.Rowindex? I'll try that and report back. How would I pick out a specific column's value using that? In other words, can you re-write this line of code using the e.Rowindex:
comboTech1.Text = wd_help_deskDataGridView.CurrentRow.Cells["help_tech"].Value.ToString();

Thanks,
Chad
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 22693738
comboTech1.Text = wd_help_deskDataGridView.Rows(e.RowIndex).Cells["help_tech"].Value.ToString();
0
 

Author Comment

by:kalittaair
ID: 22694152
webtubbs:

Thanks for the code, but I get:
"Non-invocable member 'System.Windows.Forms.DataGridView.Rows' cannot be used like a method."

As I was typing it, when I got to (e.RowIndex). Intellisense did not allow me to pick "Cells" so I figured it was going to bomb. Any ideas?
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 250 total points
ID: 22695936
Sorry, that should have been like this....

    comboTech1.Text = wd_help_deskDataGridView.Rows[e.RowIndex].Cells["help_tech"].Value.ToString();

Wayne
0
 

Author Closing Comment

by:kalittaair
ID: 31505244
Thanks Wayne!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now