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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • frostbb

    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.




  • Zhi-Xin Ye [MSFT]

    #2
    RE: Help w/ winform DataGrid to DataGridView transition (best practice?)

    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:
    msdnmg@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.

    Comment

    • frostbb

      #3
      Re: Help w/ winform DataGrid to DataGridView transition (best practice?)

      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.mic rosoft.comwrote in message
      news:lCTDII1BJH A.424@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:
      msdnmg@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.
      >

      Comment

      • Zhi-Xin Ye [MSFT]

        #4
        Re: Help w/ winform DataGrid to DataGridView transition (best practice?)

        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@microsof t.com.

        Comment

        Working...