473,388 Members | 1,355 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,388 software developers and data experts.

Help w/ winform DataGrid to DataGridView transition (best practice?)

Greetings,

We're starting to transition our legacy C# apps from earlier versions to
VS2008 versions.

Many of our apps allow the user to select a row from a DataGrid into a 'Data
Edit' area composed of Text, Combo, etc boxes that contain the individual
columns of the DataGrid row.

To extract information from the user selected DataGrid row we use the
following code ....

Given a DataGrid / DataGridView named "dgResults"

string sSelectedDirID = null;
string sSelectedGridID = null;
DataRowView oDrvSelectedGridRow = null;
try
{
oDrvSelectedGridRow =
(DataRowView)this.BindingContext[dgResults.DataSource,
dgResults.DataMember].Current;
sSelectedDirID = oDrvSelectedGridRow["Dir_id"].ToString().Trim();
sSelectedGridID = oDrvSelectedGridRow["Grid_id"].ToString().Trim();
}
catch { return;}

The best translation of the code above for a DataGridView seems to be
something like

string sSelectedDirID = null;
string sSelectedGridID = null;
DataRowView oDrvSelectedGridRow = null;
try
{
oDrvSelectedGridRow = this.dgResults.CurrentRow.DataBoundItem AS
DataRowView;
sSelectedDirID = oDrvSelectedGridRow["Dir_id"].ToString().Trim();
sSelectedGridID = oDrvSelectedGridRow["Grid_id"].ToString().Trim();
}
catch { return;}

Anyone have a better approach ?

Thanks in advance.

Barry in Oregon.


Aug 25 '08 #1
3 1813
Dear Barry,

To extract information from the user selected DataGridView row, we can
access the value directly without accessing the data source, for example,

string sSelectedDirID =
this.dataGridView1.CurrentRow.Cells["Dir_id"].Value.ToString();
string sSelectedGridID =
this.dataGridView1.CurrentRow.Cells["Grid_id"].Value.ToString();

Should you have any questions, please don't hesitate to let me knonw.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

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://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 26 '08 #2
Mr Ye (again I hope this is the correct form of address)

Thank you! Much better than having to tag the binding manager!

Barry in Oregon
"Zhi-Xin Ye [MSFT]" <v-****@online.microsoft.comwrote in message
news:lC*************@TK2MSFTNGHUB02.phx.gbl...
Dear Barry,

To extract information from the user selected DataGridView row, we can
access the value directly without accessing the data source, for example,

string sSelectedDirID =
this.dataGridView1.CurrentRow.Cells["Dir_id"].Value.ToString();
string sSelectedGridID =
this.dataGridView1.CurrentRow.Cells["Grid_id"].Value.ToString();

Should you have any questions, please don't hesitate to let me knonw.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

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://support.microsoft.com/select/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Aug 27 '08 #3
Dear Barry,

I'm glad that my suggestion helped!
And, yes, the address form you used is correct, my family name is Ye, and
I'm male. :-)

Have a nice day!

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

Aug 28 '08 #4

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

Similar topics

5
by: ComputerStop | last post by:
I am attempting to print a datagridview. I have not found any method that works successfully. Has any one been successful with this?
5
by: matthewtec | last post by:
I realize there are probably many discussions on these two... whether to get now or wait or yadda yadda yadda. My question is that I can continuing training on visual studio.net 2003, and...
17
by: Timothy.Rybak | last post by:
Hello all, This is my first attempt at an application, so kid gloves are appreciated. I need to make a very simple form that only has a few elements. One is TraceCode - a text field that is...
0
by: newtonwong | last post by:
Hi, I'm wondering whats the best practice to accomplish the following display in a DataGridView. 1. Perform a Query to an Oracle DB with a multiple join select that returns multiple rows....
0
by: Brett Romero | last post by:
I've written a DataGrid class that inhertis from DataGrid. There's a lot of code in this class specific to the DataGrid's functionality. I mainly want to use the DataGridView for drop down combo...
1
by: seanmle | last post by:
I want to build a windows application that has a datagrid filled with data. When a person modifies information on a single cell, it updates the database without the user having to click on a save...
2
by: cj | last post by:
I was looking over some of my 2003 code today (see below) that loads a foxpro table via oledb connection. I used a sub "autosizecolumns" I found on the web but I never quite understood why they...
6
by: =?Utf-8?B?R2VudGlhbiBIaWxh?= | last post by:
I have a datagrid that I want to be able to allow me to edit only the first two rows and all the other rows to be read-only. How can I do that? Any insight is highly appreciated. I have spent...
9
by: Miro | last post by:
My current headache is proper is with the datagridview I am starting to realize that a DataGridView within vs2008 is not as 'robust' as a 'textboxfield' by default for example. Example: A...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.