Jul 12, 2011, 11:27 AM
[CLOSED] Doesn't work ToolTips for ComboBox Items
Why Doesn't work ToolTips for ComboBox Items?
public class ComboBoxEasyExt : Ext.Net.ComboBox, IDisposable { private bool _ItemsToolTipsEnable = false; public bool ItemsToolTipsEnable { get { return _ItemsToolTipsEnable; } set { _ItemsToolTipsEnable = value; } } private string _DisplayField = "Name"; public string DisplayField { get { return _DisplayField; } set { _DisplayField = value; } } private string _ValueField = "Id"; public string ValueField { get { return _ValueField; } set { _ValueField = value; } } public string DataTypeName { get; set; } public string DataSourceTypeName { get; set; } private string _DataSourceMethod = "GetList"; public string DataSourceMethod { get { return _DataSourceMethod; } set { _DataSourceMethod = value; } } public string EmptyText { get; set; } public string EmptyValue { get; set; } private void LoadData() { if (!Ext.Net.X.IsAjaxRequest) { base.Items.Clear(); base.Mode = Ext.Net.DataLoadMode.Single; if (!String.IsNullOrEmpty(this.DataSourceTypeName) && !String.IsNullOrEmpty(this.DataTypeName)) { JiPSoftware.Framework.Web.SearchParameters search_params = new JiPSoftware.Framework.Web.SearchParameters(); search_params.DsTypeName = this.DataSourceTypeName; search_params.DsMethod = this.DataSourceMethod; List data = JiPSoftware.Framework.Web.SearchTools.LoadList(search_params).Cast().ToList(); bool IsExistValue = (!String.IsNullOrEmpty(this.ValueField) && !object.ReferenceEquals(JiPSoftware.Framework.Helpers.GetTypeFromString(this.DataTypeName).GetProperty(this.ValueField), null)); bool IsExistText = (!String.IsNullOrEmpty(this.DisplayField) && !object.ReferenceEquals(JiPSoftware.Framework.Helpers.GetTypeFromString(this.DataTypeName).GetProperty(this.DisplayField), null)); bool IsExistEmpty = (!String.IsNullOrEmpty(this.EmptyValue) || !String.IsNullOrEmpty(this.EmptyText)); if (IsExistEmpty) { base.Items.Add( new Ext.Net.ListItem( (!String.IsNullOrEmpty(this.EmptyText) ? this.EmptyText : string.Empty), (!String.IsNullOrEmpty(this.EmptyValue) ? this.EmptyValue : string.Empty))); } foreach (object o in data) { base.Items.Add( new Ext.Net.ListItem( (IsExistText ? o.GetType().GetProperty(this.DisplayField).GetValue(o, null).ToString() : string.Empty), (IsExistValue ? o.GetType().GetProperty(this.ValueField).GetValue(o, null).ToString() : string.Empty))); } if (IsExistEmpty) { base.Value = (!String.IsNullOrEmpty(this.EmptyValue) ? this.EmptyValue : string.Empty); } if (this.AutoWidth) { base.AutoSize(); } } } } protected override void OnDataBinding(System.EventArgs e) { LoadData(); base.OnDataBinding(e); _hasJustBound = true; } protected override void OnPreRender(System.EventArgs e) { if (!_hasJustBound) { DataBind(); } if (this.ItemsToolTipsEnable) { this.GenerateToolTips(); } base.OnPreRender(e); } private void GenerateToolTips() { base.ToolTips.Clear(); Ext.Net.ToolTip tt = new Ext.Net.ToolTip(); tt.Listeners.Show.Handler = "var record = " + this.ClientID + ".findRecord(" + this.ClientID + ".valueField, " + this.ClientID + ".getValue()); this.body.update(record ? 'Value: ' + record.get(" + this.ClientID + ".valueField) + '
Text: ' + record.get(" + this.ID + ".displayField) : 'Empty');"; base.ToolTips.Add(tt); } }
Last edited by Daniil; Jul 12, 2011 at 2:09 PM.
Reason: [CLOSED]