Problem with custom control in grid view columns

4 posts, 0 answers
  1. Juares Rigotti
    Juares Rigotti avatar
    15 posts
    Member since:
    Oct 2009

    Posted 02 Dec 2011 Link to this post

    Hello,

    I have a single custom control with one textbox and one button, I'm using my control as radgridview colum and when the grid need use scrool bar the values of my control instances mix between the different lines, for exemple the value of the first line will be last. This occurs only with last version of rad controls, I look a exemple in this forum with a similar control and download source code in old version of rad controls, functioning normally and when upgrade to last version the same problem occurred.

    Version that functioning 2010 Q2 0422

    Post that I look http://www.telerik.com/community/forums/silverlight/gridview/animating-rows-and-cells-when-data-changes.aspx

    How do I proceed?
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 06 Dec 2011 Link to this post

    Hello Eduardo Bonato,

    Would you please confirm whether you are using similar approach as in the referred thread, as it won't be applicable with the newer versions of RadControls? RadGridView implements container reusing, so that I would not advise you to change any values on your control's Loaded event, because it won't be raised when a cached container is shown in the view port.

    Best wishes,
    Ivan Ivanov
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
  3. Juares Rigotti
    Juares Rigotti avatar
    15 posts
    Member since:
    Oct 2009

    Posted 07 Dec 2011 Link to this post

    This is a code of my control, I need use the Loaded event to set valu of textbox, how to I can proced?

     

    public

     

     

    partial class lookup : UserControl, INotifyPropertyChanged

     

    {

     

     

     

    public lookup()

     

    :

     

    base()

     

    {

    InitializeComponent();

    Loaded +=

     

    new RoutedEventHandler(OnLoaded);

     

    }

     

    public event PropertyChangedEventHandler PropertyChanged;

     

     

    public virtual void OnPropertyChanged(PropertyChangedEventArgs args)

     

    {

     

    PropertyChangedEventHandler handler = this.PropertyChanged;

     

     

    if (handler != null)

     

    {

    handler(

     

    this, args);

     

    }

    }

     

    public void OnPropertyChanged(string propertyName)

     

    {

     

    this.OnPropertyChanged(new PropertyChangedEventArgs(propertyName));

     

    }

     

     

    public static string name { get; set; }

     

     

    public static Guid id { get; set; }

     

     

    public string Tipo

     

    {

     

    get { return (string)(GetValue(TipoProperty)); }

     

     

    set { SetValue(TipoProperty, value); }

     

    }

     

    public static readonly DependencyProperty TipoProperty =

     

     

    DependencyProperty.Register(

     

     

    "Tipo",

     

     

    typeof(string),

     

     

    typeof(lookup), new PropertyMetadata(string.Empty)

     

    );

     

    public static readonly DependencyProperty NameTextProperty =

     

     

    DependencyProperty.Register(

     

     

    "Nome",

     

     

    typeof(string),

     

     

    typeof(lookup), new PropertyMetadata(string.Empty)

     

    );

     

    public string Nome

     

    {

     

    get { return (string)(GetValue(NameTextProperty)); }

     

     

    set

     

    {

    SetValue(NameTextProperty,

     

    value);

     

    OnPropertyChanged(

     

    "Nome");

     

    }

    }

     

     

    public static readonly DependencyProperty IdNomeProperty =

     

     

    DependencyProperty.Register(

     

     

    "IdNome",

     

     

    typeof(Guid),

     

     

    typeof(lookup), new PropertyMetadata(Guid.Empty)

     

    );

     

    public Guid IdNome

     

    {

     

    get { return (Guid)(GetValue(IdNomeProperty)); }

     

     

    set

     

    {

    SetValue(IdNomeProperty,

     

    value);

     

    }

    }

     

    public static readonly DependencyProperty FiltroIdProperty =

     

     

    DependencyProperty.Register(

     

     

    "FiltroId",

     

     

    typeof(Guid),

     

     

    typeof(lookup), new PropertyMetadata(Guid.Empty)

     

    );

     

    public Guid FiltroId

     

    {

     

    get { return (Guid)(GetValue(FiltroIdProperty)); }

     

     

    set { SetValue(FiltroIdProperty, value); }

     

    }

     

    void textChanged_event(object sender, TextChangedEventArgs e)

     

    {

     

    if (ValueChanged != null)

     

    ValueChanged(

     

    this, new RoutedEventArgs());

     

    }

     

    private void OnLoaded(object sender, RoutedEventArgs e)

     

    {

     

    if (Nome != null)

     

    {

     

    this.txbName.Text = this.Nome;

     

    }

    }

     

     

    private void btnLookup_Click(object sender, RoutedEventArgs e)

     

    {

     

    this.txbName.TextChanged += new TextChangedEventHandler(textChanged_event);

     

    GetLookup();

    }

     

    public event RoutedEventHandler ValueChanged;

     

    [

     

    ScriptableMember]

     

     

    public void GetLookup()

     

    {

     

    if (id.ToString().Equals("00000000-0000-0000-0000-000000000000"))

     

    {

    id = FiltroId;

    }

     

    var obj = HtmlPage.Window.Invoke(Tipo, id);

     

     

    if (obj.ToString() != string.Empty)

     

    {

    id =

     

    new Guid(obj.ToString().Split(';')[0]);

     

    name = obj.ToString().Split(

     

    ';')[1];

     

    IdNome = id;

    Nome = name;

     

    this.txbName.Text = name;

     

    FiltroId = id;

    }

     

    else

     

    {

     

    this.txbName.Text = string.Empty;

     

    IdNome =

     

    Guid.Empty;

     

    }

    }

    }

    }

     

     

  4. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 08 Dec 2011 Link to this post

    Hi,

     You should use bindings instead custom code in Loaded event to avoid such problems. The grid UI virtualization will reuse UI containers (rows, cells) and this event will not be fired for the new DataContext.

    Regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top