Ejemplo n.º 1
0
 public MainForm()
 {
     InitializeComponent();
     context          = new NorthwindEntities(new Uri(@"http://localhost:56848/NorthwindWcfDataService.svc/"));
     wcfInstantSource = new WcfInstantFeedbackSource();
     wcfInstantSource.KeyExpression += "CustomerID";
     wcfInstantSource.GetSource     += new EventHandler <GetSourceEventArgs>(wcfInstantSource_GetSource);
     gridControl1.DataSource         = wcfInstantSource;
 }
        public static void BindSeverMode(this SearchLookUpEdit searchLookUpEdit, Entity entity)
        {
            if (entity == null)
            {
                return;
            }
            if (searchLookUpEdit.DataBindings.Count == 0)
            {
                return;
            }

            var binding = searchLookUpEdit.DataBindings[0];

            string attributeName = binding.BindingMemberInfo.BindingMember;

            var attribute         = entity.Attributes.FirstOrDefault(a => a.PhysicalName.Equals(attributeName));
            var lookupValue       = attribute.AttributeLookupValues.First();
            var lookupValueEntity = lookupValue.Entity;

            searchLookUpEdit.Properties.BeginInit();

            var entityName       = lookupValueEntity.PhysicalName;
            var displayAttribute =
                lookupValueEntity.Attributes.First(a => a.AttributeId == lookupValue.DisplayEntityAttributeId);

            searchLookUpEdit.Properties.DisplayMember = displayAttribute.PhysicalName;

            var primaryKeyAttribute =
                lookupValueEntity.Attributes.Single(a => a.IsPKAttribute.HasValue && a.IsPKAttribute.Value);

            searchLookUpEdit.Properties.ValueMember    = primaryKeyAttribute.PhysicalName;
            searchLookUpEdit.Properties.NullText       = string.Empty;
            searchLookUpEdit.Properties.AllowNullInput = DefaultBoolean.True;
            searchLookUpEdit.Properties.TextEditStyle  = TextEditStyles.DisableTextEditor;
            searchLookUpEdit.Properties.ShowFooter     = false;
            searchLookUpEdit.Properties.View.LoadDefaultLayout(entityName);
            searchLookUpEdit.Properties.View.InitColumns(entityName);
            var query  = searchLookUpEdit.Properties.View.CreateQuery(entityName, null, null);
            var source = new WcfInstantFeedbackSource();

            source.GetSource += (s, e) =>
            {
                e.Query         = query;
                e.KeyExpression = primaryKeyAttribute.PhysicalName;
            };
            searchLookUpEdit.Properties.DataSource = source;
            searchLookUpEdit.Properties.EndInit();
        }