OBJECT Binding

Posted by: ramnath-fp on 8 September 2017, 2:14 pm EST

  • Posted 8 September 2017, 2:14 pm EST

    /This  is city class

    public class Cls_City
        {
            public Cls_City()
            {
            }

            public Cls_City (string cityid, string cityName, string cityState)
            {
                m_Id = cityid;
                mName = cityName;
                mStateName = cityState;
            }
            private string m_Id ;
            public string Id
            {
                get { return m_Id ; }
                set { m_Id  = value; }
            }
            private string mName;

            public string CityName
            {
                get { return mName; }
                set { mName = value; }
            }
            private string mStateName;

            public string StateName
            {
                get { return mStateName; }
                set { mStateName = value; }
            }
        }

    ///// This Customer class have cls_City as propery. 

     public class Cls_Customer
        {
            public Dictionary dictionary = new Dictionary();
            public Cls_Customer(string custId, string custName, string custType, string custMobile, Cls_City custCity)
            {
                mCustid = custId;
                mType = custType;
                mName = custName;
                mMobile = custMobile;
                mCity = custCity;
            }

            private string mCustid;

            public string Id
            {
                get { return mCustid; }
                set { mCustid = value; }
            }
            private string mType;

            public string Type
            {
                get { return mType; }
                set { mType = value; }
            }
            private string mName;

            public string Name
            {
                get { return mName; }
                set { mName = value; }
            }
            private string mMobile;

            public string MobileNumber
            {
                get { return mMobile; }
                set { mMobile = value; }
            }
            private Cls_City mCity;
            public Cls_City City
            {
                get
                {
                    return mCity;
                }
                set
                {
                    mCity = City;
                }
            }

    // I want display these data in spread.

    /// How i display city and state with the help of city property of the customer class. 

     System.ComponentModel.BindingList citiesList=new BindingList();
                System.ComponentModel.BindingList cList =new BindingList();
                citiesList.Add(new Cls_City("1", "Mumbai",  "Maharashtra"));
                citiesList.Add(new Cls_City("2", "Pune", "Maharashtra"));
                citiesList.Add(new Cls_City("3", "Delhi", "UP"));
                citiesList.Add(new Cls_City("4", "Bangalore", "Karnataka"));
                citiesList.Add(new Cls_City("5", "Surat", "Gujarat"));

                cList.Add(new Cls_Customer("10", "Mahesh", "Debtor", "123654", citiesList[0]));
                cList.Add(new Cls_Customer("20", "Ravi", "Creditor", "859647", citiesList[1]));
                cList.Add(new Cls_Customer("30", "John", "Debtor", "78965", citiesList[2]));

                Sp_Cust_Sht1.DataSource = cList;
                Sp_Cust_Sht1.Columns[0].DataField = "Id";
                Sp_Cust_Sht1.Columns[1].DataField = "Type";
                Sp_Cust_Sht1.Columns[2].DataField = "Name";
                Sp_Cust_Sht1.Columns[3].DataField = "MobileNumber";
                Sp_Cust_Sht1.Columns[4].DataField = "City.CityName"; //// Not display data ??????????????????????????
               Sp_Cust_Sht1.Columns[5].DataField = "City.StateName"; //// Not display data ??????????????????????????

     

     

     

    regards,

    Ram Nath

    INDIA

  • Replied 8 September 2017, 2:14 pm EST

    Hi Ram,

    Spread does not support that syntax for sub-properties.  You would need to add properties to your customer class to wrap the properties in the city class.

    Do you know of any data bound controls which support that sort of syntax?  I can submit an enhancement request to improve this behavior, and showing other controls which already support it improves the chances of it getting implemented.

  • Replied 8 September 2017, 2:14 pm EST

    Hi,

    In farpoint inputpro we can bind like this.

    fpno.DataBindings.Add(new Binding("Text", CurrentObject, "City.StateName"));

     

    Is possible to set spread column data field like this:-

     Sp_Cust_sht1.Columns[0].DataField="City.StateName";

     

    Please repply me

    Thanks and regards,

    Ram Nath

    MUMBAI(INDIA)

  • Replied 8 September 2017, 2:14 pm EST

    Hello,

    In order to set the DataField you may use  the following approach:

                BindingList Records = new BindingList();    
                fpSpread1.ActiveSheet.AutoGenerateColumns =false;   
                fpSpread1.ActiveSheet.DataSource = Records; 
                fpSpread1.ActiveSheet.Columns[0].DataField = "StateName";

    I hope it will help you.

    Thanks,

     

     

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels