Solved

DataGridView help

Posted on 2008-10-10
10
606 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

789 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