Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

BaseEdit.CustomDisplayText Event

Enables custom display text to be provided for an editor.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.2.dll

NuGet Package: DevExpress.Win.Navigation

#Declaration

[DXCategory("Events")]
public event CustomDisplayTextEventHandler CustomDisplayText

#Event Data

The CustomDisplayText event's data class is CustomDisplayTextEventArgs. The following properties provide information specific to this event:

Property Description
DisplayText Gets or sets an editor’s display text.
Value Gets an editor’s current value.

#Remarks

The CustomDisplayText event can be used to provide custom display text for an editor. To provide custom text, assign it to the event’s DisplayText parameter.

The editor’s CustomDisplayText event is equivalent to the RepositoryItem.CustomDisplayText event available via the BaseEdit.Properties object. See RepositoryItem.CustomDisplayText for more details.

For ImageComboBoxEdit editors, the CustomDisplayText event only fires when the editor has no selected value (the ComboBoxEdit.SelectedIndex equals -1). When a value is selected, the display text is specified by the selected item’s ImageComboBoxItem.Description property.

#Example

The code below shows how to provide custom display text for a ProgressBarControl by handling the BaseEdit.CustomDisplayText event.

In the example, the ProgressBarControl displays a countdown timer.

using DevExpress.XtraEditors;

System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();

private void Form1_Load(object sender, EventArgs e) {
    progressBarControl1.Properties.ShowTitle = true;
    progressBarControl1.Properties.PercentView = false;
    progressBarControl1.CustomDisplayText += ProgressBarControl1_CustomDisplayText;
    timer.Tick += timer1_Tick;
}

private void btnStartTimer_Click(object sender, EventArgs e) {
    timer.Enabled = false;
    int totalSeconds = 5;
    DateTime startTime = DateTime.Now;
    progressBarControl1.Tag = startTime;
    progressBarControl1.Properties.Minimum = 0;
    progressBarControl1.Properties.Maximum = totalSeconds;
    progressBarControl1.Position = progressBarControl1.Properties.Minimum;
    timer.Enabled = true;
}

private void ProgressBarControl1_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e) {
    ProgressBarControl pb = sender as ProgressBarControl;
    if (pb.Tag == null) { e.DisplayText = "Stopped"; return; }
    int currentPosition = Convert.ToInt32(e.Value);
    int maximum = pb.Properties.Maximum;
    int secondsLeft = maximum - currentPosition;
    TimeSpan timeLeft = new TimeSpan(0, 0, secondsLeft);
    string s = string.Format("{0:dd} days {0:hh} hours {0:mm} minutes {0:ss} seconds", timeLeft);
    e.DisplayText = s;
}

private void timer1_Tick(object sender, EventArgs e) {
    ProgressBarControl pb = progressBarControl1;
    if (pb.Tag == null || !(pb.Tag is DateTime)) return;
    DateTime startTime = (DateTime)pb.Tag;
    DateTime currentTime = DateTime.Now;
    int elapsedSeconds = Convert.ToInt32((currentTime - startTime).TotalSeconds);
    int totalSeconds = pb.Properties.Maximum;
    if (elapsedSeconds >= totalSeconds) {
        (sender as System.Windows.Forms.Timer).Enabled = false;
        pb.Tag = null;
        BeginInvoke(new MethodInvoker(delegate
        {
            MessageBox.Show("Stop");
        }));
    }
    pb.Position = elapsedSeconds;
}
See Also