View previous topic :: View next topic |
Author |
Message |
Roel van Grinsven
Joined: 07 Jul 2010 Posts: 3 Location: Netherlands
|
Posted: Thu Jul 08, 2010 7:44 pm Post subject: virtualdropdownlist with multiple items |
|
|
High;
We are using VT 3.15
In the tree we show the structure of a truck (e.g suspension--wheel-- tyre) on the rightside we show a virtualdropdownlist (feature/options).
The new requirements wants that we show an icon before and the price after the optiondescription.
Is this possible with the VT dropdownlist? and have you an example (c#)?
Roel |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Jul 08, 2010 10:32 pm Post subject: |
|
|
I assume you are talking about the VirtualDropDownList control in the Infralution.Controls assembly? This doesn't support displaying icons and there isn't currently a way of customizing the displayed list using widgets as there is for VirtualListBox and VirtualTree. We will look at making customization possible in the next release. _________________ Infralution Support |
|
Back to top |
|
|
Roel van Grinsven
Joined: 07 Jul 2010 Posts: 3 Location: Netherlands
|
Posted: Fri Jul 09, 2010 7:02 am Post subject: |
|
|
yes, I'am talking about the VirtualDropDownList control.
For a standard Combobox i proberly would override the onpaint method, but that's not possible with the VirtualDropDownList.
You mention the Virtuallistbox. Is that an alternative (UITypeEditor) for the Combobox ?
I have seen it in the database sample (colomn color) and have you more information on it or should I try to use the standard Combobox ? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri Jul 09, 2010 7:58 am Post subject: |
|
|
I don't think that overriding OnPaint would work for the standard ComboBox either - because that would only override painting for the text part of the control - not the dynamic dropdown window. Do you actually need a VirtualDropDownList? VirtualDropDownList and VirtualListBox are designed for handling very large data sources - if your datasource is not huge then you could probably use a standard control - although you may have some difficulty getting these to paint an icon as well.
Another possibility would be to implement your own UITypeEditor and then you can use our UniversalEditBox control to display the data. This isn't trivial however. _________________ Infralution Support |
|
Back to top |
|
|
Roel van Grinsven
Joined: 07 Jul 2010 Posts: 3 Location: Netherlands
|
Posted: Fri Jul 09, 2010 9:57 pm Post subject: |
|
|
I have used a standard ComboBox within Virtual Tree and override the onDrawItem.
That did the trick.
For whom is interested I give you my solution.
// customized drawing process
protected override void OnDrawItem(DrawItemEventArgs e)
{
if (e.Index == -1) // guard
return;
if (this.Items[e.Index].GetType() != typeof(ConfigComboBoxListItem)) // guard
return;
e.DrawBackground();
e.DrawFocusRectangle();
ConfigComboBoxListItem item = (ConfigComboBoxListItem)this.Items[e.Index];
if (item.ImageString != string.Empty)
DrawImage(e, item.ImageString);
DrawComboBox(e, item);
SetComboBoxColors();
base.OnDrawItem(e);
}
private void DrawComboBox(DrawItemEventArgs e, ConfigComboBoxListItem item)
{
SolidBrush brush = new SolidBrush(e.ForeColor);
using (SolidBrush back = new SolidBrush(BackColor))
{
string showtext = item.Text;
if (ApplicationSettings.Instance.Properties.ShowSelcode)
showtext = item.Answer.SelectionCode + " " + item.Text;
e.Graphics.DrawString(showtext, e.Font, brush, e.Bounds.Left + 12 * 2, e.Bounds.Top);
//draw price
float priceWidth;
if (item.Price == decimal.MinValue)
priceWidth = 0;
else
priceWidth = e.Graphics.MeasureString(item.Price.ToString("C", Application.CurrentCulture), e.Font).Width;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds.Right - priceWidth, e.Bounds.Top, priceWidth, e.Bounds.Height);
else
e.Graphics.FillRectangle(back, e.Bounds.Right - priceWidth, e.Bounds.Top, priceWidth, e.Bounds.Height);
if (item.Price != decimal.MinValue)
e.Graphics.DrawString(item.Price.ToString("C", Application.CurrentCulture), e.Font, brush, e.Bounds.Right - priceWidth, e.Bounds.Top);
}
}
private void SetComboBoxColors()
{
if (this.Enabled)
{
this.BackColor = Color.White;
this.ForeColor = SystemColors.ControlText;
}
else
{
this.BackColor = SystemColors.Control;
this.ForeColor = SystemColors.GrayText;
}
}
private static void DrawImage(DrawItemEventArgs e, string imageString)
{
e.Graphics.DrawImage((Bitmap)Resource.ResourceManager.GetObject(imageString), e.Bounds.Left, e.Bounds.Top);
} |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sat Jul 10, 2010 12:32 am Post subject: |
|
|
Thanks for sharing that. _________________ Infralution Support |
|
Back to top |
|
|
|