This is a migrated thread and some comments may be shown as answers.

Listcontrol not reflecting the new items in the data rebind

3 Answers 9 Views
ListControl
This is a migrated thread and some comments may be shown as answers.
Sarin
Top achievements
Rank 1
Sarin asked on 14 May 2018, 11:00 AM

Hi,
I am trying to add new items to a Radlist control. I have updated the list which is the data source for the radlist control. When i do the rebind. the new items not showing in the list control.But I can see the datasource(list) has the new item(s) added.I have attached the sample code here. Add button should add the new items to list control. I also wants to achieve if any item(s) double clicked in the list control should be removed from it.Please provide me a sample for that as well.I also wants to keep the dropdownlist list by default as not selected any items(blank) .

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Common;
using System.Configuration;
 
namespace VisaManagementApp
{
    public partial class Form_Main : Form
    {
        DBHelper dbhelper = new DBHelper();
        Countries Nationalities = null;
        Countries AllowedCountries = null;
        PermittedCountries permittedCountries = null;
 
        string conString;
 
 
        public Form_Main()
        {
            InitializeComponent();
 
            this.radDDL_SourceCountry.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown;
            this.radDDL_SourceCountry.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            this.radDDL_SourceCountry.DropDownListElement.AutoCompleteSuggest.SuggestMode = SuggestMode.Contains;
 
            this.radDDL_AllowedCountry.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown;
            this.radDDL_AllowedCountry.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            this.radDDL_AllowedCountry.DropDownListElement.AutoCompleteSuggest.SuggestMode = SuggestMode.Contains;
 
            conString = ConfigurationManager.AppSettings["footPrint"];
        }
 
        private void Form_Main_Load(object sender, EventArgs e)
        {
 
            LoadNationalities();
            LoadAllowedCountries();
            Panel_Main.Location = new Point(this.ClientSize.Width / 2 - Panel_Main.Size.Width / 2, this.ClientSize.Height / 2 - Panel_Main.Size.Height / 2);
            Panel_Main.Anchor = AnchorStyles.None;
            pb_product.Location = new Point(Panel_Header.Width / 2, Panel_Header.Height / 2 - pb_product.Height / 2);
 
        }
 
        private void LoadNationalities()
        {
            Nationalities = null;
            string error = string.Empty;
            try
            {
 
                dbhelper.GetAllCountryDetails(conString, out Nationalities, out error);
               // Nationalities.Insert(0, new Country() { COUNTRY_NAME = "", COUNTRY_CODE = "" });
                this.radDDL_SourceCountry.DataSource = Nationalities;
                foreach (Country cnty in Nationalities)
                {
                    this.radDDL_SourceCountry.ValueMember = "COUNTRY_CODE";
                    this.radDDL_SourceCountry.DataMember = "COUNTRY_CODE";
                    this.radDDL_SourceCountry.DisplayMember = "COUNTRY_NAME";
                }
 
                this.radDDL_SourceCountry.DropDownListElement.EditableElement.NullText = "Search here";
            }
            catch (Exception ex)
            {
 
            }
 
        }
 
        private void LoadAllowedCountries()
        {
            AllowedCountries = null;
            string error = string.Empty;
            try
            {
                dbhelper.GetAllCountryDetails(conString, out AllowedCountries, out error);
                //AllowedCountries.Insert(0, new Country() { COUNTRY_NAME = "", COUNTRY_CODE = "" });
                radDDL_AllowedCountry.DataSource = AllowedCountries;
                foreach (Country country in AllowedCountries)
                {
                    this.radList_AllowedCountries.DisplayMember = "COUNTRY_NAME";
                    this.radList_AllowedCountries.ValueMember = "COUNTRY_CODE";
                    this.radList_AllowedCountries.DataMember = "COUNTRY_NAME";
                }
            }
            catch (Exception ex)
            {
 
            }
 
        }
 
        private void radDDL_SourceCountry_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
        {
            if (radDDL_SourceCountry.SelectedIndex != 0)
            {
                permittedCountries = null;
                Country country = null;
                string err = string.Empty;
                dbhelper.GetCountryCode(conString, radDDL_SourceCountry.SelectedItem.Text, out country, out err);
                if (country != null)
                {
                    if (radDDL_SourceCountry.SelectedIndex != 0)
                    {
                        dbhelper.GetPermittedCountries(conString, country.COUNTRY_CODE, out permittedCountries, out err);
 
                        if (permittedCountries != null)
                        {
                            this.radList_AllowedCountries.DataSource = permittedCountries;
                            foreach (PermittedCountry cnty in permittedCountries)
                            {
                                this.radList_AllowedCountries.ValueMember = "ALLOWED_COUNTRY_CODE";
                                this.radList_AllowedCountries.DataMember = "ALLOWED_COUNTRY_NAME";
                                this.radList_AllowedCountries.DisplayMember = "ALLOWED_COUNTRY_NAME";
                            }
 
                        }
 
                    }
                }
            }
 
        }
 
        private void radButton1_Click(object sender, EventArgs e)
        {
 
            try
            {
                if (radDDL_AllowedCountry.SelectedIndex != 0)
                {
 
                    permittedCountries.Insert(0, new PermittedCountry()
                    {
                        ALLOWED_COUNTRY_CODE = radDDL_AllowedCountry.SelectedItem.Value.ToString(),
                        ALLOWED_COUNTRY_NAME = radDDL_AllowedCountry.SelectedItem.Text,
                        NATIONALITY_CODE = radDDL_SourceCountry.SelectedItem.Value.ToString(),
                        STATUS = true
                    });
 
                    radList_AllowedCountries.Rebind();
 
                }
            }
            catch(Exception ex)
            {
 
            }
        }
 
    }
}


Thanks in advance

Sarin Soman

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 15 May 2018, 09:44 AM
Hello Sarin,

First I want to say that there is no need to set the DataMemberValueMember, and the DisplayMember multiple times. It would be better to set these properties once, before setting the data source.

In addition, could you share the implementation of the PermittedCountries class? Is it inheriting from a list or something else? This will give us a better understanding of your scenario.

I am looking forward to your reply.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Sarin
Top achievements
Rank 1
answered on 15 May 2018, 10:02 AM
Hi Dimitar. Thanks for the tips. Please find permitted country class.
public class PermittedCountry
   {
       public string NATIONALITY_CODE { get; set; }
       public string ALLOWED_COUNTRY_CODE { get; set; }
       public string ALLOWED_COUNTRY_NAME { get; set; }
       public bool STATUS { get; set; }       
   }
 
   public class PermittedCountries : List<PermittedCountry>
   {
 
   }
0
Dimitar
Telerik team
answered on 15 May 2018, 10:35 AM
Hi Sarin,

I have tested this with your code on my side and it appears to work. Could you please check it and let me know how it differs from your real setup? 

In addition, could you confirm that you are using the latest version of the suite? 

I am looking forward to your reply.
 
Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
ListControl
Asked by
Sarin
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Sarin
Top achievements
Rank 1
Share this question
or