Solved

DataGridView help

Posted on 2008-10-10
10
608 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ado.net AddWithValue when using IN condition 7 45
VB.net/VSTO Excel Add-in 2 38
Make borderless form movable by user 2 27
Manage big list of parameter list 8 21
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

732 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