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

ListControl problem with scrolling and styled Items

3 Answers 80 Views
ListControl
This is a migrated thread and some comments may be shown as answers.
SomeName
Top achievements
Rank 1
SomeName asked on 26 Aug 2011, 07:07 AM
Hi.

I have a "little" problem with the ListControl.
I am trying to do a little Chat thingy.. and facing a Problem when the items are formated with Styles (Font, Size, Bold...).

In my Test Application you will see some controls.
1.) ListControl that stores the written messages
2.) A TextBox to input the desired Text message
3.) 2 Buttons with the text 1 and 20 - The 20 Button just calls the 1 button 20 times
    The 1 Button, inserts 3 Items into the ListControl 
        1st a HeaderItem with the UserName and the DateTime
        2nd a TextItem with the given Text
        3rd a FooterItem to get a space between Messages
4.) An indicator for the Items.Count Value of the ListControl


So now the Problems i have after i have added some Messages to the ListControl and do some scrolling at some Point you will notice 3 Errors.
1.) The last Item doesnt get selected (not Highlighted with the Orange Color)
2.) The scrolling doesnt work. The Scrollelement moves but the ListControl seems like frozen.
3.) No new Items get displayed, tough it works - Item Counter goes still up.

Another Problem is that when i call the 20 Buttons at first after the form loads, the last item doesnt get selected. But this isnt really an issue that i am facing in reall application, because this button only exists in this test application so that you can add items faster, since you need some. (Second time hitting this button selects list item fine, only doesnt work when hitting it at first)

Hope you guys can help me fix those problems, already tried some LayoutUpdates but no luck till now. :(

And a side Note Question, is there a way to change the HighLight MouseOver and the Select Color?

Source Code for test Application:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
 
public partial class RadForm1 : RadForm
{
    public RadForm1()
    {
        InitializeComponent();
 
        radTextBox1.Text = "Some random Text!";
        radListControl1.AutoSizeItems = true;
 
        radTextBox1.Font = new Font("Times New Roman", 10, FontStyle.Bold);
        radTextBox1.TextBoxElement.ForeColor = Color.Red;
        radListControl1.SelectionMode = SelectionMode.One;
    }
 
    List<int> ids = new List<int>();
    private int GetNewId()
    {
        int returnValue = 0;
        do
        {
            returnValue = new Random().Next(int.MaxValue);
        } while (ids.IndexOf(returnValue) >= 0);
        ids.Add(returnValue);
 
        return returnValue;
    }
 
    private void radButton1_Click(object sender, EventArgs e)
    {
        RadListDataItem itemHeader = new RadListDataItem(string.Format("<html><b>{0}</b> ({1})</html>", "Some User", DateTime.Now), GetNewId());
        radListControl1.Items.Add(itemHeader);
 
        RadListDataItem itemText = new RadListDataItem(radTextBox1.Text, GetNewId());
        itemText.TextWrap = true;
        itemText.Font = radTextBox1.Font;
        itemText.ForeColor = radTextBox1.TextBoxElement.ForeColor;
        radListControl1.Items.Add(itemText);
 
        RadListDataItem itemFooter = new RadListDataItem("   ", GetNewId());
        radListControl1.Items.Add(itemFooter);
 
        radListControl1.SelectedItem = itemFooter;
        radTextBox2.Text = radListControl1.Items.Count.ToString();
    }
 
    private void radButton2_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < 20; i++)
        {
            radButton1_Click(null, null);
        }
    }
}


Designer:

partial class RadForm1
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;
 
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }
 
    #region Windows Form Designer generated code
 
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
            this.radListControl1 = new Telerik.WinControls.UI.RadListControl();
            this.radTextBox1 = new Telerik.WinControls.UI.RadTextBox();
            this.radButton1 = new Telerik.WinControls.UI.RadButton();
            this.radButton2 = new Telerik.WinControls.UI.RadButton();
            this.radTextBox2 = new Telerik.WinControls.UI.RadTextBox();
            this.label1 = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.radListControl1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.radTextBox1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.radButton1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.radButton2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.radTextBox2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            this.SuspendLayout();
            //
            // radListControl1
            //
            this.radListControl1.CaseSensitiveSort = true;
            this.radListControl1.ItemHeight = 18;
            this.radListControl1.Location = new System.Drawing.Point(12, 12);
            this.radListControl1.Name = "radListControl1";
            this.radListControl1.Size = new System.Drawing.Size(274, 229);
            this.radListControl1.TabIndex = 0;
            this.radListControl1.Text = "radListControl1";
            //
            // radTextBox1
            //
            this.radTextBox1.Location = new System.Drawing.Point(12, 247);
            this.radTextBox1.Name = "radTextBox1";
            this.radTextBox1.Size = new System.Drawing.Size(192, 20);
            this.radTextBox1.TabIndex = 1;
            this.radTextBox1.TabStop = false;
            this.radTextBox1.Text = "radTextBox1";
            //
            // radButton1
            //
            this.radButton1.Location = new System.Drawing.Point(211, 247);
            this.radButton1.Name = "radButton1";
            this.radButton1.Size = new System.Drawing.Size(33, 24);
            this.radButton1.TabIndex = 2;
            this.radButton1.Text = "1";
            this.radButton1.Click += new System.EventHandler(this.radButton1_Click);
            //
            // radButton2
            //
            this.radButton2.Location = new System.Drawing.Point(250, 247);
            this.radButton2.Name = "radButton2";
            this.radButton2.Size = new System.Drawing.Size(36, 24);
            this.radButton2.TabIndex = 3;
            this.radButton2.Text = "20";
            this.radButton2.Click += new System.EventHandler(this.radButton2_Click);
            //
            // radTextBox2
            //
            this.radTextBox2.Location = new System.Drawing.Point(211, 277);
            this.radTextBox2.Name = "radTextBox2";
            this.radTextBox2.Size = new System.Drawing.Size(75, 20);
            this.radTextBox2.TabIndex = 4;
            this.radTextBox2.TabStop = false;
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(153, 277);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(52, 13);
            this.label1.TabIndex = 5;
            this.label1.Text = "Counter:";
            //
            // RadForm1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(298, 303);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.radTextBox2);
            this.Controls.Add(this.radButton2);
            this.Controls.Add(this.radButton1);
            this.Controls.Add(this.radTextBox1);
            this.Controls.Add(this.radListControl1);
            this.Name = "RadForm1";
            //
            //
            //
            this.RootElement.ApplyShapeToControl = true;
            this.Text = "RadForm1";
            this.ThemeName = "ControlDefault";
            ((System.ComponentModel.ISupportInitialize)(this.radListControl1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.radTextBox1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.radButton1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.radButton2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.radTextBox2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();
 
    }
 
    #endregion
 
    private Telerik.WinControls.UI.RadListControl radListControl1;
    private Telerik.WinControls.UI.RadTextBox radTextBox1;
    private Telerik.WinControls.UI.RadButton radButton1;
    private Telerik.WinControls.UI.RadButton radButton2;
    private Telerik.WinControls.UI.RadTextBox radTextBox2;
    private System.Windows.Forms.Label label1;
}


3 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Todorov
Telerik team
answered on 31 Aug 2011, 08:42 AM
Hi,

Thank you for contacting us.

This appears to be an issue in RadListControl. For some reason, after some scrolling and adding items, the layout remains suspended. We will address this in a future release. I have logged this to PITS so you can subscribe to it. You can find the PITS item by following this link. Your Telerik points have been updated for bringing our attention to this issue.

To overcome this, I have added a ResumeLayout call in your click handler. The problem with adding 20 items at once is present because you are calling the radButton1_Click method in a for cycle and the layout is not performed during it. Adding a PerformLayout call in your click handler prevents this behavior. Here are the modifications:
private void radButton1_Click(object sender, EventArgs e)
{
    RadListDataItem itemHeader = new RadListDataItem(string.Format("<html><b>{0}</b> ({1})</html>", "Some User", DateTime.Now), GetNewId());
    radListControl1.Items.Add(itemHeader);
 
    RadListDataItem itemText = new RadListDataItem(radTextBox1.Text, GetNewId());
    itemText.TextWrap = true;
    itemText.Font = radTextBox1.Font;
    itemText.ForeColor = radTextBox1.TextBoxElement.ForeColor;
    radListControl1.Items.Add(itemText);
 
    RadListDataItem itemFooter = new RadListDataItem("   ", GetNewId());
    radListControl1.Items.Add(itemFooter);
      
    this.radListControl1.ListElement.ResumeLayout(true, true);
    this.radListControl1.PerformLayout();
 
    radListControl1.SelectedItem = itemFooter;
    radTextBox2.Text = radListControl1.Items.Count.ToString();
}

Hope this is useful. Feel free to ask if you have any additional questions.

All the best,
Ivan Todorov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
SomeName
Top achievements
Rank 1
answered on 05 Sep 2011, 01:34 PM
Thanks for the answer works fine. Voted for this in the mentioned PITS system.

But, you didnt answer my side note question, so i gona ask it again. Dont really want to open a new thread for such a small thing, so...
"And a side Note Question, is there a way to change the HighLight MouseOver and the Select Color?"
0
Ivan Todorov
Telerik team
answered on 08 Sep 2011, 12:09 PM
Hello,

Please excuse me for my omission.

You can change these colors by modifying the default theme in Visual Style Builder. This is a tool which helps users to create/modify the visual appearance of of our controls. More information about it can be found on its corresponding help section. The attached screenshot demonstrates how to select and modify the color of the selected or hovered states.

I hope this helps. If you have any further questions, do not hesitate to contact me.

Greetings,
Ivan Todorov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
ListControl
Asked by
SomeName
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
SomeName
Top achievements
Rank 1
Share this question
or