Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

DataGridView help

Posted on 2008-10-10
10
Medium Priority
?
613 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 48

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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

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 48

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 48

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 48

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 1000 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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

647 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