I try to find some examples for overriding ext.net combobox. I need to do this, because I want to use default values for most properties. But I have a problem. I could not to find some examples for store, handler, proxy and my own listeners which using in combobox. How can I override it? Can anybody give me some examples?
A C# class example for own combobox. My thanks.
Edit...
public class CombinedComboBox : ComboBox
{
#region Properties
private string _handlerAddress;
private Store _store;
private StoreParameterCollection _storeParameters;
private ModelFieldCollection _modelFields;
private ListenerCollection _listeners;
public string HandlerAddress
{
get { return _handlerAddress; }
set
{
if (!value.StartsWith("/Handlers/"))
_handlerAddress = "/Handlers/" + value;
else
_handlerAddress = value;
}
}
public StoreParameterCollection StoreParameters
{
get { return _storeParameters; }
set { _storeParameters = value; }
}
public ModelFieldCollection ModelFields
{
get { return _modelFields; }
set { _modelFields = value; }
}
#endregion
#region ASP.NET Controls Init & Events
public CombinedComboBox()
{
//Базовые автоматические значения, также можно просадить в Init
HideLabel = false;
DisplayField = "Name";
PageSize = 10;
TypeAhead = true;
LabelWidth = 160;
MinChars = 2;
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
BuildStore();
if (!AllowBlank) AfterLabelTextTpl.Html = "<span style=\"color: red; font - weight: bold\" data-qtip=\"Required\">*</span>";
}
private void BuildStore()
{
_store = new Store
{
AutoLoad = false,
RemotePaging = true,
RemoteFilter = true,
IsPagingStore = true,
PageSize = PageSize
};
_store.Proxy.Add(new AjaxProxy
{
Json = true,
ActionMethods = { Read = HttpMethod.GET },
Url = HandlerAddress,
Reader = { new JsonReader { Root = "data", TotalProperty = "total" } }
});
if (_storeParameters != null && _storeParameters.Count > 0)
{
foreach (var item in _storeParameters)
{
_store.Parameters.Add(item);
}
}
_store.AutoLoadParams.Add(new Parameter("start", "0"));
_store.AutoLoadParams.Add(new Parameter("limit", PageSize.ToString()));
Model model = new Model { IDProperty = "Id" };
model.Fields.Add(new ModelField("Id", ModelFieldType.String));
model.Fields.Add(new ModelField("Name", ModelFieldType.String));
if (_modelFields != null && _modelFields.Count > 0)
{
foreach (var item in _modelFields)
{
model.Fields.Add(item);
}
}
_store.Model.Add(model);
Bin.Add(_store);
}
#endregion
}
My WebForm:
<elem:CombinedComboBox
ID="MyId"
runat="server"
EmptyText="Text"
FieldLabel="Text"
HandlerAddress="/Handlers/OrgStructureDirectionsListHandler.ashx">
<StoreParameters>
<ext:StoreParameter Name="DirectionType" Value="SomeDirection" Mode="Value" />
</StoreParameters>
<Listeners>
<Select Fn="ItemSelected"/>
</Listeners>
</elem:CombinedComboBox>
But Handler never called. Why?
Ok, I found a problem. It was because I didn't place ID for my store like this:
protected override void OnPreRender(EventArgs e)
{
StoreID = _store.ClientID;
base.OnPreRender(e);
}
Related
I have created a small form and a user control , but I don't know how to pass data from one side of the database to the other user control , followed some tutorials on the net and I used the (get;set) pair like that. this:
IN Main form
string query = #"select t.Ma_Nvu,t.Ten_Nvu,t.Time_Start,t.Time_End,d.Noi_dung from ToDoList_ListNvu t
left join ToDoList_NoiDungNvu d on t.Ma_Nvu = d.Ma_Nvu
where t.Status like N'Chưa hoàn thành'";
dt = (new Data()).executeQuery(query);
if (dt.Rows.Count == 0)
{
MessageBox.Show("Bạn cần tạo nhiệm vụ trước để vào !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
ProcessToDoList tdl = new ProcessToDoList();
BunifuTransition trans = new BunifuTransition();
this.PageToDoList.Controls.Add(tdl);
tdl.Location = new Point(0, 0);
tdl.Size = new Size(0, 567);
if (tdl.Width == 0)
{
tdl.Width = 1014;
trans.ShowSync(tdl, false, Bunifu.UI.WinForms.BunifuAnimatorNS.Animation.HorizBlind);
tdl.BringToFront();
}
foreach (DataRow dr in dt.Rows)
{
DataList data = new DataList();
data.Name = dr["Ten_Nvu"].ToString();
data.Time_Start = dr["Time_Start"].ToString();
data.Time_End = dr["Time_End"].ToString();
data.Noi_Dung = dr["Noi_dung"].ToString();
dtaAdd.Add(data);
}
int i = 0;
while (i < dt.Rows.Count)
{
tdl.Name_Nvu = dtaAdd[i].Name;
tdl.Noi_dung = dtaAdd[i].Noi_Dung;
tdl.Time_Start = dtaAdd[i].Time_Start;
tdl.Time_End = dtaAdd[i].Time_End;
if (tdl.CheckOut()==true)
{
i++;
}
}
In UserControl
public string Name_Nvu
{
get { return _name; }
set { _name = value; }
}
public string Noi_dung
{
get {return _noidung ; }
set {_noidung = value; }
}
public string Time_Start
{
get { return _timestart; }
set { _timestart = value; }
}
public string Time_End
{
get { return _timeend; }
set { _timeend = value; }
}
But it doesn't work. I don't know where the error is, so I want to ask everyone how can I pass data from form to user control.
I'm not sure what error message ur getting, but passing value from your form to your UC could be done this way.
In your User Control:
private string _name;
[Category("Custom Props")]
public string custom_name
{
get { return _name; }
set { _name = value; }
}
Then in your form, you can assign value to the _name string in the user control by doing something like this:
myUC test = new myUC(); //Your user control
test.custom_name = dtaAdd[i].Name;
panel1.Controls.Add(test);
I want to add a tooltip to a menu item. On the menu there is the word "DELETE" and when the mouse hovers over the word I want a tooltip displayed. I though of using 'ToolTipService.SetToolTip();'.
This is where the items contained in the menu are set...
protected virtual void SetContextMenuItems()
{
// -- Add condition for ReadOnly + ReadOnly Attribute to AreaEntity
if (this.ViewMode == Common.Core.ViewModes.RealTime)
{
AreaEntity ae = viewModel.EntityViewContext as AreaEntity;
if (((UserContext.Instance.IsAdmin() && (ae.Scope.Value == "global" || ae.Scope.Value == string.Empty)) ||
ae.OwnerPosition.Value == CoreServices.Instance.CurrentPosition.Configuration.Name)
&& !((this.MapInstance.Parent as Grid).Parent is PIPMap))
{
menuItem = new ContextMenuItem();
//menuItem.DisplayText = "Delete"; // -- Could be dynamic based off type "Edit Polygon (Circle, etc.)"
menuItem.DisplayText = CoreServices.Instance.GetString("Delete");
cmd = new MR.CommandBridge.Common.Command.DelegateCommand(DeleteShape, CanDelete);
menuItem.Command = cmd;
this.ContextMenu.MenuItems.Add(menuItem);
}
}
}
Methods 'DeleteShape' and 'CanDelete':
public void DeleteShape(object param)
{
EntityStore.Instance.DeleteEntity(this.ViewModel.EntityViewContext);
}
public bool CanDelete(object param)
{
GetRulesForShape();
bool isInFilter = false;
EntityCollection<Entity> lists = EntitySync.Instance.Cache["entityCollection"];
foreach (Entity list in lists)
{
isInFilter = (list as ListEntity).FilterList.Filters.Count(a => (a.FilterType == FilterTypes.WithinZone && a.Value == this.viewModel.EntityViewContext.Uri) ||
(a.FilterType == FilterTypes.MultipleFilter && a.Filters.Count(b => b.FilterType == FilterTypes.WithinZone && b.Value == this.viewModel.EntityViewContext.Uri) > 0)) > 0;
if (isInFilter) break;
}
return !HasRules && !CoreServices.Instance.ZoneFilters.Contains(this.viewModel.Area.Uri) && gfEditor.dm != GeofenceEditor.DrawMode.DrawEdit && !isInFilter;
}
Ok I made some adjustments to your class.
Somehow I got the feeling your mixing up things like control and bindings.
We'll see. ;)
I've also made some comments, maybe you can shed some light over then.
public class ContextMenuItem : MenuItem
{
public ContextMenuItem()
:base()
{
}
//Replace by Header
//
//public string DisplayText { get; set; }
//Can this be replaced by build in CommandParameter
//
private Dictionary<string, object> _parameters = new Dictionary<string, object>();
private Func<ContextMenuItem, List<ContextMenuItem>> _getMenuItems = null;
//Already available
//public DelegateCommand Command { get; set; }
//What does this function do?
public Func<ContextMenuItem, List<ContextMenuItem>> GetMenuItems
{
get
{
return _getMenuItems;
}
set
{
_getMenuItems = value;
}
}
public Dictionary<string, object> Parameters
{
get
{
return _parameters;
}
}
//Can be replaced by base Items
//
//private List<ContextMenuItem> _menuItems = new List<ContextMenuItem>();
//public List<ContextMenuItem> ChildMenuItems
//{
// get
// {
// return _menuItems;
// }
//}
private bool _isChecked = false;
public bool IsChecked
{
get { return _isChecked; }
set { _isChecked = value; }
}
// -- Command or implementer could provide a handler for all commands - might be simpler for now
// -- I think there could be a better way to route commands but I'll thin on it.
Could this simply be done in .css?
.yourclass:hover{
cursor:pointer;
}
or target it with jquery?
Have you tried this?
menuitem.ToolTip = "Delete";
Normally a contextmenu can exist of regular MenuItems. I used it often.
;)
Context menu items have the ToolTipText property:
menuItem.ToolTipText = "ToolTip Text Here";
I'm trying to insert a protobuf-net object into my MongoDB. The object looks something like this:
message Measurement
{
optional string _someString1 = 1 [default = ""];
optional string _someString2 = 2 [default = ""];
repeated MyMessage1 _myMessages1 = 3;
repeated MyMessage2 _myMessages2 = 4;
repeated MyMessage3 _myMessages3 = 5;
}
MyMessage1..3 are messages in the same proto file and they contain a few strings, doubles and int64s.
I fill an instance of Measurement with some data and try to insert it into my DB, like this:
var col = MyDatabase.GetCollection<Measurement>("Measurements");
col.Insert(instanceOfMeasurement);
Now, if I check on the contents of the DB, I can see that the instanceOfMeasurement has been added correctly. But the repeated fields within haven't. Do I need to prepare a more complex object in some way, before stuffing it into MongoDB?
Okay, here is what protobuf-net creates:
[global::System.Serializable, global::ProtoBuf.ProtoContract(Name=#"Measurement")]
public partial class Measurement : global::ProtoBuf.IExtensible, global::System.ComponentModel.INotifyPropertyChanged
{
public Measurement() {}
private string __someString1;
[global::ProtoBuf.ProtoMember(1, IsRequired = false, Name=#"_someString1", DataFormat = global::ProtoBuf.DataFormat.Default)]
public string _SomeString1
{
get { return __someString1?? ""; }
set { __someString1 = value; OnPropertyChanged(#"_someString1"); }
}
[global::System.Xml.Serialization.XmlIgnore]
[global::System.ComponentModel.Browsable(false)]
public bool _someString1Specified
{
get { return this.__someString1 != null; }
set { if (value == (this.__someString1== null)) this.__someString1 = value ? this._someString1 : (string)null; }
}
private bool ShouldSerialize_someString1() { return _someString1Specified; }
private void Reset_someString1() { _someString1Specified = false; }
private string __someString2;
[global::ProtoBuf.ProtoMember(2, IsRequired = false, Name=#"_someString2", DataFormat = global::ProtoBuf.DataFormat.Default)]
public string _SomeString2
{
get { return __someString2?? ""; }
set { __someString2 = value; OnPropertyChanged(#"_someString2"); }
}
[global::System.Xml.Serialization.XmlIgnore]
[global::System.ComponentModel.Browsable(false)]
public bool _someString2Specified
{
get { return this.__someString2 != null; }
set { if (value == (this.__someString2== null)) this.__someString2 = value ? this._someString2 : (string)null; }
}
private bool ShouldSerialize_someString2() { return _someString2Specified; }
private void Reset_someString2() { _someString2Specified = false; }
private readonly global::System.Collections.Generic.List<MyMessage1> __myMessages1 = new global::System.Collections.Generic.List<MyMessage1>();
[global::ProtoBuf.ProtoMember(6, Name=#"_myMessages1", DataFormat = global::ProtoBuf.DataFormat.Default)]
public global::System.Collections.Generic.List<MyMessage1> _myMessages1
{
get { return __myMessages1; }
}
private readonly global::System.Collections.Generic.List<MyMessage2> __myMessages2 = new global::System.Collections.Generic.List<MyMessage2>();
[global::ProtoBuf.ProtoMember(7, Name=#"_myMessages2", DataFormat = global::ProtoBuf.DataFormat.Default)]
public global::System.Collections.Generic.List<MyMessage2> _myMessages2
{
get { return __myMessages2; }
}
private readonly global::System.Collections.Generic.List<MyMessage3> __myMessages3 = new global::System.Collections.Generic.List<MyMessage3>();
[global::ProtoBuf.ProtoMember(8, Name=#"_myMessages3", DataFormat = global::ProtoBuf.DataFormat.Default)]
public global::System.Collections.Generic.List<MyMessage3> _myMessages3
{
get { return __myMessages3; }
}
public event global::System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{ if(PropertyChanged != null) PropertyChanged(this, new global::System.ComponentModel.PropertyChangedEventArgs(propertyName)); }
private global::ProtoBuf.IExtension extensionObject;
global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
{ return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); }
}
The driver doesn't by default serialize properties that have no setter. Evidently that includes the messages on Measurement.
To override the default behavior and include these properties* you either mark them with the BsonElement attribute or map them with RegisterClassMap. In this case where the classes are auto-generated an attribute would be a bad idea so use the latter:
BsonClassMap.RegisterClassMap<Measurement>(m =>
{
m.MapProperty(x => x.MyMessage1);
m.MapProperty(x => x.MyMessage2);
m.MapProperty(x => x.MyMessage3);
});
More in Serialize Documents with the C# Driver: Opt In
* When a readonly property is serialized, it value is persisted to the database, but never read back out. This is useful for storing “computed” properties
I have a rather strange requirement for a Wpf Project I'm working on. I want to be able to build a XamDataGrid with a series of DateTime fields when the user saves the data from another grid. Currently I see the second XamDataGrid with it's fields, but upon execution of the command that saves the data, although I can see in the debugger that my second list (which is bound to the second XamDataGrid) is generated, nothing displays on this second XamDataGrid.
I'll post most of my code so that somebody might help me:
The xaml (for the second datagrid as the first one is working fine):
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>
<igDP:Field Label="ID" Name="id" Width="50"></igDP:Field>
<igDP:Field Label="Descripcion" Name="descripcion" Width="400"></igDP:Field>
<igDP:UnboundField Label="Fechas de Pago" Name="cadaPago" Width="400">
</igDP:UnboundField>
<igDP:Field Label="Colores" Name="Colores" Visibility="Collapsed" />
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
`
The code in my viewmodel for the second grid:
public List<ClaseFechasPago> ListaFechasPago
{
get { return listaFechasPago; }
set { listaFechasPago = value; notifyChanges("ListaFechasPago"); }
}
public void PintarFechas(List<ClaseFechasPago> f)
{
ListaFechasPago.Clear();
foreach (ClaseFechasPago fecha in f)
{
fecha.cadaPago = new List<DateTime>();
for (int i = 0; i < fecha.numPagos; i++)
{
fecha.cadaPago.Add(new DateTime());
}
ListaFechasPago.Add(fecha);
}
}
public vmCursos_y_Diplomados()
{
Comando = new cmdCursos_y_Diplomados();
Comando.ViewModel = this;
ListaCursosyDiplomados = new List<ClaseCursosyDiplomados>();
ListaFechasPago = new List<ClaseFechasPago>();
this.cargarDatos();
this.PintarFechas(ListaFechasPago);
}
Now on the command I'm doing the following
public void Execute(object parameter)
{
List<CatEntidadesEducacionContinua> cursos = new List<CatEntidadesEducacionContinua>();
List<ClaseFechasPago> fechas = new List<ClaseFechasPago>();
foreach (ClaseCursosyDiplomados C in ViewModel.ListaCursosyDiplomados.Where(t=>t.Colores==1).ToList())
{
cursos.Add(new CatEntidadesEducacionContinua
{
IdEntidadEducacionContinua = C.id, Coordinador=C.coordinador, Descripcion=C.descripcion, FechaUltimoCambio = DateTime.Now,
FechaInicio = C.fechaInicio, FechaTermino=C.fechaTermino, Precio=C.precio, NumeroDePagos=C.numeroDePagos, FechasPagos=C.fechasPagos, Inhabilitado=C.inhabilitado,
});
if (C.numeroDePagos > 1)
{
ClaseFechasPago f = new ClaseFechasPago();
f.numPagos = C.numeroDePagos;
f.descripcion = C.descripcion;
f.id = C.id;
fechas.Add(f);
}
}
System.Windows.MessageBox.Show(new Entidades.MetodoCursos_y_Diplomados().SetEntidadEContinua(cursos), "Entidades de Educación Continua", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
//System.Windows.MessageBox.Show(new Entidades.MetodoFechasPago().pintarFechasPago
ViewModel.cargarDatos();
ViewModel.PintarFechas(fechas);
}
But as I said it's not working, the execution results in the following screenshot, where the second grid is not populated:
Oh and I also forgot earlier to show the code for my custom class, out of which the list bound to the XamDataGrid is made of:
public class ClaseFechasPago : Utils.PropertyChange
{
private List<DateTime> _cadaPago;
public List<DateTime> cadaPago
{
get { return _cadaPago; }
set
{
_cadaPago = value;
if (EntroPrimeraVez)
{
Colores = 1;
}
}
}
private int? _numPagos;
public int? numPagos
{
get { return _numPagos; }
set
{
_numPagos = value;
if (EntroPrimeraVez)
{
Colores = 1;
}
}
}
private int _id;
public int id
{
get { return _id; }
set
{
_id = value;
}
}
private string _descripcion;
public string descripcion
{
get { return _descripcion; }
set { _descripcion = value; }
}
private int _Colores;
private bool _EntroPrimeraVez;
public bool EntroPrimeraVez
{
get { return _EntroPrimeraVez; }
set { _EntroPrimeraVez = value; notifyChanges("EntroPrimeraVez"); }
}
public int Colores
{
get { return _Colores; }
set { _Colores = value; notifyChanges("Colores"); }
}
}
It turned out the only thing I needed to do was passing the List explicitly as a list, like so:
ListaFechasPago = ListaFechasPago.ToList()
However, I seemed to have a mistake of concept in the way I was building the date fields. I ended up building as many registries as were needed of the same entry and binding a DateTime field to each, like so:
public static List<ClaseFechasPago> PintarFechas(ClaseFechasPago f)
{
List<ClaseFechasPago> ListaFechasPago = new List<ClaseFechasPago>();
for (int i = 0; i < f.numPagos; i++)
{
ClaseFechasPago fecha = new ClaseFechasPago();
fecha.cuotaInscripcion = 0M;
fecha.Inscripcion = true;
fecha.fechaPago = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
fecha.id = f.id;
fecha.descripcion = f.descripcion;
fecha.numPagos = f.numPagos;
fecha.Colores = f.Colores;
fecha.EntroPrimeraVez = f.EntroPrimeraVez;
ListaFechasPago.Add(fecha);
}
return ListaFechasPago;
//ListaFechasPago = ListaFechasPago.ToList();
}
Oh and of course initialize the ListaFechasPago List in the class that is set as DataContext for the window:
ListaFechasPago = new List<ClaseFechasPago>();
insde the class vmCursos_y_Diplomados
because I do:
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
this.DataContext = new vmCursos_y_Diplomados();
}
This fails:
dtaAutomaticFlag.DataBindings.Add("Checked", BndSource, "AutomaticFlag");
most probably because AutomaticFlag is defined as:
public SqlByte AutomaticFlag { get; set; }
SQL Server is tinyint. The reason is that i dont only need 0 and 0 as values.
I need to be checked if the value is 1 , unchecked for ALL other values.
One thing that i thought is to create an extra property AutomaticFlagBoolean in my class and check the AutomaticFlag and bind to the new property.
This is what i tried but i get always false:
private SqlByte _automaticFlag;
public SqlByte AutomaticFlag
{
get { return _automaticFlag; }
set
{
if (_automaticFlagBoolean)
{
_automaticFlag = 1;
}
else
{
_automaticFlag = 0;
}
}
}
private bool _automaticFlagBoolean;
public bool AutomaticFlagBoolean
{
get
{
if (_automaticFlag == 1)
{
return _automaticFlagBoolean = true;
}
else
{
return _automaticFlagBoolean = false;
}
}
set { _automaticFlagBoolean = value; }
}
this is in my binding:
dtaAutomaticFlag.DataBindings.Add("Checked", BndSource, "AutomaticFlagBoolean");
The checkbox control expects a boolean value for binding.
Try using a local variable to hold the value:
private SqlByte _automaticFlag;
private bool _automaticFlagBoolean;
public SqlByte AutomaticFlag
{
get { return _automaticFlag; }
set
{
_automaticFlag = value;
_automaticFlagBoolean = (_automaticFlag != 0);
}
}
public bool AutomaticFlagBoolean
{
get
{
return _AutomaticFlagBookean;
}
set { _automaticFlagBoolean = value;
if (_automaticFlagBoolean) {
_automaticFlag = 1;
} else {
_automaticFlag = 0;
}
}
}
Then bind as so:
dtaAutomaticFlag.DataBindings.Add("Checked", BndSource, "AutomaticFlagBoolean");
Your class should also implement INotifyPropertyChanged as well but that's a little beyond the scope of your question.