Accessing other items in datasource

5 posts, 1 answers
  1. Sam
    Sam avatar
    14 posts
    Member since:
    Apr 2011

    Posted 30 Oct 2014 Link to this post

    I have a dropdownlist bound to a data source with 3 items, iid, cPolicyNo, GroupFundID
    I need to reference both iid and groupfundid when the user selects an item.

    The method I am trying to use is as below however I am getting an error:

        Error 1 Cannot convert type 'Telerik.WinControls.UI.RadListDataItem' to 'System.Data.DataRow' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion


    Thanks for any help.




        private void Underwriting_Load(object sender, EventArgs e)
            {

                this.vPolicyNoForCBOTableAdapter.Fill(this.rG.vPolicyNoForCBO);

                // Load CBO Source
                this.cboPolicyNo.DataBindings.Clear();
                this.cboPolicyNo.DataSource = this.rG.vPolicyNoForCBO;
                this.cboPolicyNo.DisplayMember = "cPolicyNo";
                
                
            }

            private void cboPolicyNo_SelectedValueChanged(object sender, EventArgs e)
            {
                // TheSWShop 103014 Find Policy
                // Behavior - Allow the user to search for the Policy Number, cbo follows this behavior.
                //            In original system, once the first 3 letters are typed pull all of the related Policy Data.
                //            Get latest Year for Policy
                //            Get Group Fund

                DataRow cboPolicyRow = (this.cboPolicyNo.SelectedItem as DataRow);

                var groupfundid = cboPolicyRow["groupfundid"].ToString();

                this.groupFundID = Int32.Parse(groupfundid);

             }
  2. Answer
    Jeff
    Jeff avatar
    2 posts
    Member since:
    Aug 2011

    Posted 30 Oct 2014 in reply to Sam Link to this post

    You'll want to find the selected item as a radlistdataitem first, then get the databound item of that object.  Seeing as the databound item will be a view of the row, you'll want to get the DataBoundItem.Row object to return the DataRow

    DataRow cboPolicyRow = (this.cboPolicyNo.SelectedItem.DataBoundItem.Row as DataRow);
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Sam
    Sam avatar
    14 posts
    Member since:
    Apr 2011

    Posted 31 Oct 2014 in reply to Jeff Link to this post

    Jeff, 

    Thanks very much for the reply, The DataBoundItem does not have the Row property.  
  5. Jeff
    Jeff avatar
    2 posts
    Member since:
    Aug 2011

    Posted 31 Oct 2014 in reply to Sam Link to this post

    It'll just be returned to you as a generic object - you'll probably need to define a conversion to a DataRowView
  6. Sam
    Sam avatar
    14 posts
    Member since:
    Apr 2011

    Posted 31 Oct 2014 in reply to Jeff Link to this post

    Jeff, Thanks very much for the assistance - That worked.



    DataRowView cboPolicyRow = (this.cboPolicyNo.SelectedItem.DataBoundItem as DataRowView);

     var groupfundid = cboPolicyRow.Row.ItemArray[2];
Back to Top
UI for WinForms is Visual Studio 2017 Ready