| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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. |
|
#2
| |||
| |||
| 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: msdnmg@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. |
|
#3
| |||
| |||
| 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-zhye@online.microsoft.com> wrote in message news:lCTDII1BJHA.424@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: > msdnmg@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. > |
|
#4
| |||
| |||
| 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: msdnmg@microsoft.com. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.