473,756 Members | 2,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 oDrvSelectedGri dRow = null;
try
{
oDrvSelectedGri dRow =
(DataRowView)th is.BindingConte xt[dgResults.DataS ource,
dgResults.DataM ember].Current;
sSelectedDirID = oDrvSelectedGri dRow["Dir_id"].ToString().Tri m();
sSelectedGridID = oDrvSelectedGri dRow["Grid_id"].ToString().Tri m();
}
catch { return;}

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

string sSelectedDirID = null;
string sSelectedGridID = null;
DataRowView oDrvSelectedGri dRow = null;
try
{
oDrvSelectedGri dRow = this.dgResults. CurrentRow.Data BoundItem AS
DataRowView;
sSelectedDirID = oDrvSelectedGri dRow["Dir_id"].ToString().Tri m();
sSelectedGridID = oDrvSelectedGri dRow["Grid_id"].ToString().Tri m();
}
catch { return;}

Anyone have a better approach ?

Thanks in advance.

Barry in Oregon.


Aug 25 '08 #1
3 1833
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.dataGridVi ew1.CurrentRow. Cells["Dir_id"].Value.ToString ();
string sSelectedGridID =
this.dataGridVi ew1.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****@microsof t.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.mic rosoft.comwrote in message
news:lC******** *****@TK2MSFTNG HUB02.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.dataGridVi ew1.CurrentRow. Cells["Dir_id"].Value.ToString ();
string sSelectedGridID =
this.dataGridVi ew1.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****@microsof t.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****@microsof t.com.

Aug 28 '08 #4

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

Similar topics

5
7105
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
1260
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 continue to learn and be able to be an experienced programmer. And I fully realize that I'd obviously be missing out on some functionality. However, in the actual phase of getting a job, does anyone have any thoughts that would suggest I would get...
17
3554
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 populated when a user scans a label. The other is ScanDate - a date/time field that should equal the date/time of the scan (e.g. 7/31/2006 5:00:00 AM).
0
1060
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. (Should I use a DB object i.e. Stored Procedure, Function, View, or nothing) 2. Bind the rows/data to a DataGridView via DataAdapter or
0
1250
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 boxes. I thought about creating another custom type class for DataGridView and possibly use a composite class to bring in all of the CustomDataGrid's functionality. I was hoping to override the DataGridView's DataSource and assign to the...
1
3805
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 button. Any ideas on how I can accomplish this? Thanks, Sean
2
1776
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 said the style name had to be the same as the table name. Perhaps the are refering to ts1.mappingname must be the same as the table name (datagrid1.datamember) because I've read that that is how the datagrid associates a style with what it's...
6
8645
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 couple of days on research but no luck so far. Thank you
9
3423
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 Textbox field can have masking, you can add easy validation and so on. Just adding a dummy datagridview to a form, databounding it, and allowing editing works - but is not dummy proof.
0
9456
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10032
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9872
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9841
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9711
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.