Search Results

Search found 854 results on 35 pages for 'databinding'.

Page 1/35 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • WPF Databinding- Not your fathers databinding Part 1-3

    - by Shervin Shakibi
    As Promised here is my advanced databinding presentation from South Florida Code camp and also Orlando Code camp. you can find the demo files here. http://ssccinc.com/wpfdatabinding.zip Here is a quick description of the first demos, there will be 2 other Blogposting in the next few days getting into more advance databinding topics.   Example00 Here we have 3 textboxes, The first textbox mySourceElement Second textbox has a binding to mySourceElement and Path= Text <Binding ElementName="mySourceElement" Path="Text"  />   Third textbox is also bound to the Text property but we use inline Binding <TextBlock Text="{Binding ElementName=mySourceElement,Path=Text }" Grid.Row="2" /> Here is the entire XAML     <Grid  >           <Grid.RowDefinitions >             <RowDefinition Height="*" />             <RowDefinition Height="*" />             <RowDefinition Height="*" />         </Grid.RowDefinitions>         <TextBox Name="mySourceElement" Grid.Row="0"                  TextChanged="mySourceElement_TextChanged">Hello Orlnado</TextBox>         <TextBlock Grid.Row="1">                        <TextBlock.Text>                 <Binding ElementName="mySourceElement" Path="Text"  />             </TextBlock.Text>         </TextBlock>         <TextBlock Text="{Binding ElementName=mySourceElement,Path=Text }" Grid.Row="2" />     </Grid> </Window> Example01 we have a slider control, then we have two textboxes bound to the value property of the slider. one has its text property bound, the second has its fontsize property bound. <Grid>      <Grid.RowDefinitions >          <RowDefinition Height="40px" />          <RowDefinition Height="40px" />          <RowDefinition Height="*" />      </Grid.RowDefinitions>      <Slider Name="fontSizeSlider" Minimum="5" Maximum="100"              Value="10" Grid.Row="0" />      <TextBox Name="SizeTextBox"                    Text="{Binding ElementName=fontSizeSlider, Path=Value}" Grid.Row="1"/>      <TextBlock Text="Example 01"                 FontSize="{Binding ElementName=SizeTextBox,  Path=Text}"  Grid.Row="2"/> </Grid> Example02 very much like the previous example but it also has a font dropdown <Grid>      <Grid.RowDefinitions >          <RowDefinition Height="20px" />          <RowDefinition Height="40px" />          <RowDefinition Height="40px" />          <RowDefinition Height="*" />      </Grid.RowDefinitions>      <ComboBox Name="FontNameList" SelectedIndex="0" Grid.Row="0">          <ComboBoxItem Content="Arial" />          <ComboBoxItem Content="Calibri" />          <ComboBoxItem Content="Times New Roman" />          <ComboBoxItem Content="Verdana" />      </ComboBox>      <Slider Name="fontSizeSlider" Minimum="5" Maximum="100" Value="10" Grid.Row="1" />      <TextBox Name="SizeTextBox"      Text="{Binding ElementName=fontSizeSlider, Path=Value}" Grid.Row="2"/>      <TextBlock Text="Example 01" FontFamily="{Binding ElementName=FontNameList, Path=Text}"                 FontSize="{Binding ElementName=SizeTextBox,  Path=Text}"  Grid.Row="3"/> </Grid> Example03 In this example we bind to an object Employee.cs Notice we added a directive to our xaml which is clr-namespace and the namespace for our employee Class xmlns:local="clr-namespace:Example03" In Our windows Resources we create an instance of our object <Window.Resources>     <local:Employee x:Key="MyEmployee" EmployeeNumber="145"                     FirstName="John"                     LastName="Doe"                     Department="Product Development"                     Title="QA Manager" /> </Window.Resources> then we bind our container to the that instance of the data <Grid DataContext="{StaticResource MyEmployee}">         <Grid.RowDefinitions>             <RowDefinition Height="*" />             <RowDefinition Height="*" />             <RowDefinition Height="*" />             <RowDefinition Height="*" />             <RowDefinition Height="*" />         </Grid.RowDefinitions>         <Grid.ColumnDefinitions >             <ColumnDefinition Width="130px" />             <ColumnDefinition Width="178*" />         </Grid.ColumnDefinitions>     </Grid> and Finally we have textboxes that will bind to that textbox         <Label Grid.Row="0" Grid.Column="0">Employee Number</Label>         <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path=EmployeeNumber}"></TextBox>         <Label Grid.Row="1" Grid.Column="0">First Name</Label>         <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=FirstName}"></TextBox>         <Label Grid.Row="2" Grid.Column="0">Last Name</Label>         <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Path=LastName}" />         <Label Grid.Row="3" Grid.Column="0">Title</Label>         <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Path=Title}"></TextBox>         <Label Grid.Row="4" Grid.Column="0">Department</Label>         <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding Path=Department}" />

    Read the article

  • Databinding a multiselect ListBox in a FormView control

    - by drs9222
    I have a multiselect ListBox within a FormView. I can't figure out how to setup the databinding for it. I can populate the listbox fine. If the listbox was a single select I could use say SelectValue='<%#Bind("col")%>' and that works fine. Is there something that I can bind to for a multiselect listbox? I've tried manually DataBinding by handling the DataBinding event of the listbox and setting the selected property on the appropriate items. Unfortunately, there are no items in the listbox during the DataBinding event. The closest thing I've found is to save the value that determines what items should be selecting during DataBinding and then use that value in the FormViews DataBinding event to select the right items which seems like a hack to me. Is there a better way? EDIT: To clarify what I am currently doing... I am using the FormViews's ItemCreated event to save the FormView's DataItem. Then in the FormView's DataBound event I find the listbox and manually set the selected items. It doesn't seem right that I have to save the value like this and I assume there is a more correct way to do this that I just can't see.

    Read the article

  • Android: databinding when using a ArrayAdapter: possible?

    - by Peterdk
    I need some simple databinding for a Spinner. I want to display 2 items for each dropdownitem. So when the user clicks the spinner I get a list like: ------------------- Name 123456 ------------------- Name 123456 ------------------- I understand this can be done when using a Cursor, according to the databinding info on android dev. Like: SimpleCursorAdapter adapter2 = new SimpleCursorAdapter(this, R.layout.my_custom_spinner_item_layout, cur, new String[] {People.NAME, People.ID}, new int[] {android.R.id.text1, android.R.id.text2}); However, I don't get my data from a database, so I don't use a cursor, I use a ArrayAdapter. Unfortunately it looks like there is no support for databinding with this adapter. Is there a way to do this?

    Read the article

  • Databinding between UserControls?

    - by Dave
    I've got a situation where one of my UserControls would like to display a list of strings in a droplist, and the ItemsSource is set to another UserControl's ObservableCollection. The consumer of this data has its droplist defined in XAML like this: <ComboBox Grid.Column="1" SelectedItem="{Binding MyItem, Mode=TwoWay}" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.MyItems}" Margin="3"></ComboBox> MyItems is defined as an ObservableCollection<string> in the producer UserControl. Now everything works fine when the controls are loaded. As long as MyItems is populated first, and then the consumer UserControl is displayed, all of the items are there. I obviously don't get any errors in the Output Window or anything like that. The issue I have is that when the ObservableCollection is modified, those changes are not reflected in the consumer UserControl! I've never had this problem before, but all of my previous uses of ObservableCollection with updating the collection are within a single control, and databinding is not inter-UserControl. Is there something I did wrong? Is there a good way to actually debug this? Reed Copsey indicates here that inter-UserControl databinding is possible. Unfortunately, my favorite Bea Stollnitz article on WPF databinding debugging doesn't suggest anything that I could use for this particular problem.

    Read the article

  • Custom Repeater with hiractial Databinding

    - by Dooie
    Im using a Custom NestedRepeater Control for ASP.NET which can be found on code project The source is in c# which i have converted to vb and plugged into my solution, so far so good. The problem, im having is databinding to the repeater, my code behind looks like this... '' get all pages Dim navPages As DataSet = Navigation.getMenuStructure() navPages.Relations.Add(navPages.Tables(0).Columns("ID"), navPages.Tables(0).Columns("ParentID")) NestedRepeaterNavigation.RelationName = RelationName NestedRepeaterNavigation.DataSource = navPages NestedRepeaterNavigation.RowFilterTop = "ParentID is null" NestedRepeaterNavigation.DataBind() Then in the item template of my custom repeater im trying the following... <ItemTemplate> <img src="/pix.gif" height="10" width="<%#(Container.Depth * 10)%>"> <%# (Container.DataItem as DataRow)["DESCRIPTION"]%> <%# (Container.NbChildren != 0 ? "<small><i>(" + Container.NbChildren.ToString() +")</i></small>" "") %><small><i></i></small> </ItemTemplate> The databinding falls over; firstly that 'as DataRow' says it was expecting an ')'. And secondly that '!=' identifier expected. Is this due to the translation from c#, should the databinding be different?

    Read the article

  • How to create databinding over two xaml files?

    - by BionicGecko
    Hello, I am trying to come to a working understanding of how databinding works, but even after several tutorials I only have a basic understanding of how databinding works. Thus this question might seem fundamental to those more familiar with silverlight. Even if it is trivial, please point me to some tutorial that deals with this problem. All that I could find simply solved this via adding the data binding on a parent page.xaml (that i must not use in my case). For the sake of this example let us assume, that we have 5 files: starter.cs button1.xaml + codeBehind button2.xaml + codeBehind The two buttons are generated in code in the starter(.cs) file, and then added to some MapLayer button1 my_button1 = new button1(); button2 my_button1 = new button2(); someLayer.Children.Add(my_button1); someLayer.Children.Add(my_button2); My aim is to connect the two buttons, so that they always display the same "text" (i.e. my_button1.content==my_button2.content = true;). Thus when something changes my_button1.content this change should be propagated to the other button (two way binding). At the moment my button1.xaml looks like this: <Grid x:Name="LayoutRoot"> <Button x:Name="x_button1" Margin="0,0,0,0" Content="{Binding ElementName=x_button2, Path=Content}" ClickMode="Press" Click="button1_Click"/> </Grid> But everthing that i get out of that is a button with no content at all, it is just blank as the binding silently fails. How could I create the databinding in the context I described? Preferably in code and not XAML ;) Thanks in advance

    Read the article

  • Databinding to ObservableCollection in a different UserControl?

    - by Dave
    Question re-written on 2010-03-24 I have two UserControls, where one is a dialog that has a TabControl, and the other is one that appears within said TabControl. I'll just call them CandyDialog and CandyNameViewer for simplicity's sake. There's also a data management class called Tracker that manages information storage, which for all intents and purposes just exposes a public property that is an ObservableCollection. I display the CandyNameViewer in CandyDialog via code behind, like this: private void CandyDialog_Loaded( object sender, RoutedEventArgs e) { _candyviewer = new CandyViewer(); _candyviewer.DataContext = _tracker; candy_tab.Content = _candyviewer; } The CandyViewer's XAML looks like this (edited for kaxaml): <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Page.Resources> <DataTemplate x:Key="CandyItemTemplate"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="120"></ColumnDefinition> <ColumnDefinition Width="150"></ColumnDefinition> </Grid.ColumnDefinitions> <TextBox Grid.Column="0" Text="{Binding CandyName}" Margin="3"></TextBox> <!-- just binding to DataContext ends up using InventoryItem as parent, so we need to get to the UserControl --> <ComboBox Grid.Column="1" SelectedItem="{Binding SelectedCandy, Mode=TwoWay}" ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.CandyNames}" Margin="3"></ComboBox> </Grid> </DataTemplate> </Page.Resources> <Grid> <ListBox DockPanel.Dock="Top" ItemsSource="{Binding CandyBoxContents, Mode=TwoWay}" ItemTemplate="{StaticResource CandyItemTemplate}" /> </Grid> </Page> Now everything works fine when the controls are loaded. As long as CandyNames is populated first, and then the consumer UserControl is displayed, all of the names are there. I obviously don't get any errors in the Output Window or anything like that. The issue I have is that when the ObservableCollection is modified from the model, those changes are not reflected in the consumer UserControl! I've never had this problem before; all of my previous uses of ObservableCollection updated fine, although in those cases I wasn't databinding across assemblies. Although I am currently only adding and removing candy names to/from the ObservableCollection, at a later date I will likely also allow renaming from the model side. Is there something I did wrong? Is there a good way to actually debug this? Reed Copsey indicates here that inter-UserControl databinding is possible. Unfortunately, my favorite Bea Stollnitz article on WPF databinding debugging doesn't suggest anything that I could use for this particular problem.

    Read the article

  • Drawing a WPF UserControl with DataBinding to an Image

    - by LorenVS
    Hey Everyone, So I'm trying to use a WPF User Control to generate a ton of images from a dataset where each item in the dataset would produce an image... I'm hoping I can set it up in such a way that I can use WPF databinding, and for each item in the dataset, create an instance of my user control, set the dependency property that corresponds to my data item, and then draw the user control to an image, but I'm having problems getting it all working (not sure whether databinding or drawing to the image is my problem) Sorry for the massive code dump, but I've been trying to get this working for a couple of hours now, and WPF just doesn't like me (have to learn at some point though...) My User Control looks like this: <UserControl x:Class="Bleargh.ImageTemplate" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:c="clr-namespace:Bleargh" x:Name="ImageTemplateContainer" Height="300" Width="300"> <Canvas> <TextBlock Canvas.Left="50" Canvas.Top="50" Width="200" Height="25" FontSize="16" FontFamily="Calibri" Text="{Binding Path=Booking.Customer,ElementName=ImageTemplateContainer}" /> <TextBlock Canvas.Left="50" Canvas.Top="100" Width="200" Height="25" FontSize="16" FontFamily="Calibri" Text="{Binding Path=Booking.Location,ElementName=ImageTemplateContainer}" /> <TextBlock Canvas.Left="50" Canvas.Top="150" Width="200" Height="25" FontSize="16" FontFamily="Calibri" Text="{Binding Path=Booking.ItemNumber,ElementName=ImageTemplateContainer}" /> <TextBlock Canvas.Left="50" Canvas.Top="200" Width="200" Height="25" FontSize="16" FontFamily="Calibri" Text="{Binding Path=Booking.Description,ElementName=ImageTemplateContainer}" /> </Canvas> </UserControl> And I've added a dependency property of type "Booking" to my user control that I'm hoping will be the source for the databound values: public partial class ImageTemplate : UserControl { public static readonly DependencyProperty BookingProperty = DependencyProperty.Register("Booking", typeof(Booking), typeof(ImageTemplate)); public Booking Booking { get { return (Booking)GetValue(BookingProperty); } set { SetValue(BookingProperty, value); } } public ImageTemplate() { InitializeComponent(); } } And I'm using the following code to render the control: List<Booking> bookings = Booking.GetSome(); for(int i = 0; i < bookings.Count; i++) { ImageTemplate template = new ImageTemplate(); template.Booking = bookings[i]; RenderTargetBitmap bitmap = new RenderTargetBitmap( (int)template.Width, (int)template.Height, 120.0, 120.0, PixelFormats.Pbgra32); bitmap.Render(template); BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmap)); using (Stream s = File.OpenWrite(@"C:\Code\Bleargh\RawImages\" + i.ToString() + ".png")) { encoder.Save(s); } } EDIT: I should add that the process works without any errors whatsoever, but I end up with a directory full of plain-white images, not text or anything... And I have confirmed using the debugger that my Booking objects are being filled with the proper data... EDIT 2: Did something I should have done a long time ago, set a background on my canvas, but that didn't change the output image at all, so my problem is most definitely somehow to do with my drawing code (although there may be something wrong with my databinding too)

    Read the article

  • Chain of DataBinding

    - by Neir0
    Hello I am trying to do follow DataBinding Property -> DependencyProperty -> Property But i have trouble. For example, We have simple class with two properties implements INotifyPropertyChanged: public class MyClass : INotifyPropertyChanged { private string _num1; public string Num1 { get { return _num1; } set { _num1 = value; OnPropertyChanged("Num1"); } } private string _num2; public string Num2 { get { return _num2; } set { _num2 = value; OnPropertyChanged("Num2"); } } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string e) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(e)); } } And TextBlock declared in xaml: <TextBlock Name="tb" FontSize="20" Foreground="Red" Text="qwerqwerwqer" /> Now lets trying to bind Num1 to tb.Text: private MyClass _myClass = new MyClass(); public MainWindow() { InitializeComponent(); Binding binding1 = new Binding("Num1") { Source = _myClass, Mode = BindingMode.OneWay }; Binding binding2 = new Binding("Num2") { Source = _myClass, Mode = BindingMode.TwoWay }; tb.SetBinding(TextBlock.TextProperty, binding1); //tb.SetBinding(TextBlock.TextProperty, binding2); var timer = new Timer(500) {Enabled = true,}; timer.Elapsed += (sender, args) => _myClass.Num1 += "a"; timer.Start(); } It works well. But if we uncomment this string tb.SetBinding(TextBlock.TextProperty, binding2); then TextBlock display nothing. DataBinding doesn't work! How can i to do what i want?

    Read the article

  • DataContext, DataBinding and Element Binding in Silverlight

    - by Matt
    I'm having one hell of a time trying to get my databinding to work correctly. I have reason to believe that what I'm trying to accomplish can't be done, but we'll see what answers I get. I've got a UserControl. This UserControl contains nothing more than a button. Now within the code behind, I've got a property name IsBookmarked. When IsBookmarked is set, code is run that animates the look of the button. The idea is that you click the button and it visually changes. We'll call this UserControl a Bookmark control. Now I have another control, which we'll call the FormControl. My FormControl contains a child Bookmark control. I've tried to do databinding on my Bookmark control, but it's not working. Here's some code to help you out. <UserControl ......> <q:Bookmark x:Name="BookMarkControl1" IsBookmarked="{Binding IsSiteBookmarked}" /> </UserControl> public void Control_Loaded(object sender, EventArgs e) { DataContext = new Employee { IsSiteBookmarked = True }; } public partial class Bookmark : UserControl { bool _IsSiteBookmarked= false; public bool IsSiteBookmarked { get {return _IsSiteBookmarked;} set { _IsSiteBookmarked= value; SwitchMode(value); } } }

    Read the article

  • Databinding combobox selected item to settings

    - by Tuukka
    I store user specified settings using application settings properties and databinding. It has been working fine, until i want user selected to font for combobox. Databinding between user settings and combobox not working. I want to store font family name. App.XML <Application.Resources> <ResourceDictionary> <properties:Settings x:Key="Settings" /> </ResourceDictionary> </Application.Resources> Window.XML <ComboBox Name="Families" ItemsSource="{x:Static Fonts.SystemFontFamilies}" <!-- This line --> SelectedItem="{Binding Source={StaticResource Settings}, Path=Default.Font, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Margin="57,122,199,118"> <ComboBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding}" FontFamily="{Binding}"/> </DataTemplate> </ComboBox.ItemTemplate> </ComboBox> Settings: font String User Arial

    Read the article

  • Slow Databinding setup time in C# .NET 4.0

    - by Svisstack
    Hello, I have got a problem. I have windows forms application with dynamic generated layout, but i have a problem in performance. In this form i use DataBinding from .NET 4.0 and databinding after setup works fine, but he binding setup time for ONE control blocking my application on approx 0.7 second. I have some controls and time of binging setuping is around 2 minutes. I trying all possible solutions, I dont have any ideas without write self binding class. Why is wrong with my code? case "Boolean": { Binding b = new Binding("Checked", __bindingsource, __ep.Name); CheckBox cb = new CheckBox(); /* * HERE is the problem */ cb.DataBindings.Add(b); /* * HERE is the end of problem */ __flp.Controls.Add(cb); __bindingcontrol.AddBinding(b); break; } Without problem code lines all works fast and without binding ;-( but i want binding turn on in normal speed. PS1. I have suspended layout in generation time. PS2. I have same problem with binding TextBox'es, PictureBoxe's, CheckBox is only example. How to do that?

    Read the article

  • WPF DataBinding, CollectionViewSource, INotifyPropertyChanged

    - by plotnick
    First time when I tried to do something in WPF, I was puzzled with WPF DataBinding. Then I studied thorougly next example on MSDN: http://msdn.microsoft.com/en-us/library/ms771319(v=VS.90).aspx Now, I quite understand how to use Master-Detail paradigm for a form which takes data from one source (one table) - both for master and detailed parts. I mean for example I have a grid with data and below the grid I have a few fields with detailed data of current row. But how to do it, if detailed data comes from different but related tables? for example: you have a Table 'Users' with columns - 'id' and 'Name'. You also have another table 'Pictures' with columns like 'id','Filename','UserId'. And now, using master-detail paradigm you have to built a form. And every time when you chose a row in a Master you should get all associated pictures in Details. What is the right way to do it? Could you please show me an example?

    Read the article

  • Winforms checkbox Databinding problem

    - by Savvas Sopiadis
    Hello everybody! In a winforms application (VB, VS2008 SP1) i bound a checkbox field to a SQL Server 2005 BIT field. The databinding itself seems to work, there is this litte problem: user creates a new record and checks the checkbox, then the user decides to create a new record (without having saved the previous, so there are 2 new records to be submitted) and checks also the second. Now the user decides to save these records: the result is that only the second record keeps the checked value, the first one is unchecked! (i tried the same with 5 records: the result is the same, the first 4 records are unchecked and only the last one keeps the checked state). What do i miss?? Thanks in advance

    Read the article

  • WPF databinding update comboxbox2 based on selection change in combobox1 with MVVM

    - by cody
    I have a combo box that I have bound to a list that exists in my viewmodel. Now when a users makes a selection in that combo box I want a second combo box to update its content. So, for example, combobox1 is States and combobox2 should contain only the Zipcodes of that state. But in my case I don't have a predefined lists before hand for combobox2, I need to go fetch from a db. Also, if needed, I could get all the potential values for combobox2 (for each combobox1 value) before hand, but I'd like to avoiding that if I can. How do I implement in WPF and using MVVM? I'm fairly new to this whole wpf\databinding\mvvm world.

    Read the article

  • Two-way databinding of a custom templated asp.net control

    - by Jason
    I hate long code snippets and I'm sorry about this one, but it turns out that this asp.net stuff can't get much shorter and it's so specific that I haven't been able to generalize it without a full code listing. I just want simple two-way, declarative, edit-only databinding to a single instance of an object. Not a list of objects of a type with a bunch of NotImplementedExceptions for Add, Delete, and Select, but just a single view-state persisted object. This is certainly something that can be done but I've struggled with an implementation for years. This newest, closest implementation was inspired by this article from 4-Guys-From-Rolla. Unfortunately, after implementing, I'm getting the following error and I don't know what I'm missing: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. If I don't use Bind(), and only use Eval() functionality, it works. In that way, the error is especially confusing. Update: Actually, using Eval() does NOT work, but using <%# Container.SampleString %> works. However, Eval("SampleString") gives the same error. That leads me back to this article I found earlier but had discarded. Now I believe it might be related, though I haven't cracked it yet ... Here's the simplified codeset that still produces the error: using System.ComponentModel; namespace System.Web.UI.WebControls.Special { public class SampleFormData { public string SampleString = "Sample String Data"; public int SampleInt = -1; } [ToolboxItem(false)] public class SampleSpecificFormDataContainer : DataBoundControl, INamingContainer { SampleSpecificEntryForm entryForm; internal SampleSpecificEntryForm EntryForm { get { return entryForm; } } [Bindable(true), Category("Data")] public string SampleString { get { return entryForm.FormData.SampleString; } set { entryForm.FormData.SampleString = value; } } [Bindable(true), Category("Data")] public int SampleInt { get { return entryForm.FormData.SampleInt; } set { entryForm.FormData.SampleInt = value; } } internal SampleSpecificFormDataContainer(SampleSpecificEntryForm entryForm) { this.entryForm = entryForm; } } public class SampleSpecificEntryForm : WebControl, INamingContainer { #region Template private IBindableTemplate formTemplate = null; [Browsable(false), DefaultValue(null), TemplateContainer(typeof(SampleSpecificFormDataContainer), ComponentModel.BindingDirection.TwoWay), PersistenceMode(PersistenceMode.InnerProperty)] public virtual IBindableTemplate FormTemplate { get { return formTemplate; } set { formTemplate = value; } } #endregion #region Viewstate SampleFormData FormDataVS { get { return (ViewState["FormData"] as SampleFormData) ?? new SampleFormData(); } set { ViewState["FormData"] = value; SaveViewState(); } } #endregion public override ControlCollection Controls { get { EnsureChildControls(); return base.Controls; } } private SampleSpecificFormDataContainer formDataContainer = null; [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public SampleSpecificFormDataContainer FormDataContainer { get { EnsureChildControls(); return formDataContainer; } } [Bindable(true), Browsable(false)] public SampleFormData FormData { get { return FormDataVS; } set { FormDataVS = value; } } protected override void CreateChildControls() { if (!this.ChildControlsCreated) { Controls.Clear(); formDataContainer = new SampleSpecificFormDataContainer(this); Controls.Add(formDataContainer); FormTemplate.InstantiateIn(formDataContainer); this.ChildControlsCreated = true; } } public override void DataBind() { CreateChildControls(); base.DataBind(); } } } With an ASP.NET page the following: <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default2.aspx.cs" Inherits="EntryFormTest._Default2" EnableEventValidation="false" %> <%@ Register Assembly="EntryForm" Namespace="System.Web.UI.WebControls.Special" TagPrefix="cc1" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <h2> Welcome to ASP.NET! </h2> <cc1:SampleSpecificEntryForm ID="EntryForm1" runat="server"> <FormTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("SampleString") %>'></asp:TextBox><br /> <h3>(<%# Container.SampleString %>)</h3><br /> <asp:Button ID="Button1" runat="server" Text="Button" /> </FormTemplate> </cc1:SampleSpecificEntryForm> </asp:Content> Default2.aspx.cs using System; namespace EntryFormTest { public partial class _Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { EntryForm1.DataBind(); } } } Thanks for any help!

    Read the article

  • Inherited properties aren't bound during databinding

    - by Josh
    I have two interfaces, IAuditable and ITransaction. public interface IAuditable{ DateTime CreatedOn { get; } string CreatedBy { get; } } public interface ITransaction : IAuditable { double Amount{ get; } } And a class that implements ITransaction, call Transaction. public class Transaction : ITransaction{ public DateTime CreatedOn { get { return DateTime.Now; } } public string CreatedBy { get { return "aspnet"; } } public doubl Amount { get { return 0; } } } When I bind a list of ITransactions to a datagrid and use auto create columns, only the Amount gets bound. The CreatedBy and CreatedOn are not seen. Is there a way I can get these values visible during databinding?

    Read the article

  • How to make Databinding type safe and support refactoring

    - by Ian Ringrose
    When I wish to bind a control to a property of my object, I have to provide the name of the property as a string. This is not very good because: If the property is removed or renamed, I don’t get a compiler warning. If a rename the property with a refactoring tool, it is likely the data binding will not be updated. I don’t get an error until runtime if the type of the property is wrong, e.g. binding an integer to a date chooser. Is there a design-paten that gets round this, but still has the ease of use of data-binding? (This is a problem in WinForm, Asp.net and WPF and most likely lots of other systems) I have now found "workarounds for nameof() operator in C#: typesafe databinding" that also has a good starting point for a solution.

    Read the article

  • XML databinding to TreeView (or Tab control), bind attribute based on different attribute

    - by Number8
    Hello, I have some xml: <Test> <thing location="home" status="good"/> <thing location=work" status="bad"/> <thing location="mountains" status="good"/> </Test> The leaves on the TreeView are the values of the status attribute; the nodes will be the value of the location attribute. +--bad ¦.....+--work +--good .......+--home .......+--mountains Currently, I populate the TreeView (or Tab control) manually, iterating through the xml, adding the nodes to the appropriate leaf. Can this be done via databinding? I'm guessing a Converter will be involved... Thanks for any advice.

    Read the article

  • Databinding Error when Recreating object

    - by Maxim Gershkovich
    Hi All, Figure there is a simple solution to this problem but I have been unable to find it. I have databinding in an ASP.Net application to a GridView. This gridview is bound to an ObjectDataSource as per standard usage. The problem I have is that one of my bound fields uses the property DataFormatString="{0:C}" and due to the currency format being displayed when an update is attempted and the object recreated I get a error as such "$13.00 is not a valid value for Decimal." Clearly this is a result of the column using a FormatString and then attempting to bind it back to a decimal property I have in my object called UnitPrice. I am assuming there is some markup I can set that can specify how the value is translated back? Thanks in advance for any help.

    Read the article

  • DataBinding to GridView

    - by liran
    Hello, I Have a gridview object and i want to bind it to Object.. My Object is namespace DataBinding { public class BindingObject { public ColorInfo Color { get; set; } public string Name { get; set; } public struct ColorInfo { public string Red { get; set; } public string Green { get; set; } public string Blue { get; set; } } } } I want that in the gridview i will see only the Name Property And Red property.. Now when i bound it my gridview see like this: Color column and Name Column and i want Red column and Name Column.. How i do this.. Thanks..

    Read the article

  • WPF - databinding ObservableCollection CollectionChanged event?

    - by e0eight
    Hi, I have an observable collection implemented in my user control which indicates states of a device. Based on the collection change, the user control is to trigger animations(subscribe to collectionchanged event). The observable collection is implemented as a dependency property. In the application, I data bind the device states to the user control observableCollection using one-way databinding. When a new state is added in the application, I can see the ObservableCollection in the user control is updated. However, the CollectionChanged event never got fired, so no animations. Does anyone has an idea why this is so? Thank you in advance.

    Read the article

  • 'EditItem' is not allowed for this view - databinding issue

    - by Pawan
    Hi, I am trying to do data binding in WPF on data grid using a cutom list. My custom list class contains a private data list of type List. I can not expose this list however the indexers are exposed for seeting and getting individual items. My custom class looks like this: public abstract class TestElementList<T> : IEnumerable where T : class { protected List<T> Data { get; set; } public virtual T Get(int index) { T item = Data[index]; return item; } public virtual void Set(int index, T item) { Data[index] = item; } ... } The data is binded but when I try to edit it, i get "'EditItem' is not allowed for this view." Error. On doing extensive searching over web, I found that i might need to implement IEditableCollectionView interface also. Can anybody please help me to either give pointers on how to implement this interface or any suggest any other better way to do databinding on custom list. Thanks in advance.

    Read the article

  • WPF Databinding CheckBox.IsChecked

    - by Adam Tegen
    How would I bind the IsChecked member of a CheckBox to a member variable in my form? (I realize I can access it directly, but I am trying to learn about databinding and WPF) Below is my failed attempt to get this working. XAML: <Window x:Class="MyProject.Form1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Title" Height="386" Width="563" WindowStyle="SingleBorderWindow"> <Grid> <CheckBox Name="checkBoxShowPending" TabIndex="2" Margin="0,12,30,0" Checked="checkBoxShowPending_CheckedChanged" Height="17" VerticalAlignment="Top" HorizontalAlignment="Right" Width="92" Content="Show Pending" IsChecked="{Binding ShowPending}"> </CheckBox> </Grid> </Window> Code: namespace MyProject { public partial class Form1 : Window { private ListViewColumnSorter lvwColumnSorter; public bool? ShowPending { get { return this.showPending; } set { this.showPending = value; } } private bool showPending = false; private void checkBoxShowPending_CheckedChanged(object sender, EventArgs e) { //checking showPending.Value here. It's always false } } }

    Read the article

  • NHibernate, Databinding to DataGridView, Lazy Loading, and Session managment - need advice

    - by Tom Bushell
    My main application form (WinForms) has a DataGridView, that uses DataBinding and Fluent NHibernate to display data from a SQLite database. This form is open for the entire time the application is running. For performance reasons, I set the convention DefaultLazy.Always() for all DB access. So far, the only way I've found to make this work is to keep a Session (let's call it MainSession) open all the time for the main form, so NHibernate can lazy load new data as the user navigates with the grid. Another part of the application can run in the background, and Save to the DB. Currently, (after considerable struggle), my approach is to call MainSession.Disconnect(), create a disposable Session for each Save, and MainSession.Reconnect() after finishing the Save. Otherwise SQLite will throw "The database file is locked" exceptions. This seems to be working well so far, but past experience has made me nervous about keeping a session open for a long time (I ran into performance problems when I tried to use a single session for both Saves and Loads - the cache filled up, and bogged down everything - see http://stackoverflow.com/questions/2526675/commit-is-very-slow-in-my-nhibernate-sqlite-project). So, my question - is this a good approach, or am I looking at problems down the road? If it's a bad approach, what are the alternatives? I've considered opening and closing my main session whenever the user navigates with the grid, but it's not obvious to me how I would do that - hook every event from the grid that could possibly cause a lazy load? I have the nagging feeling that trying to manage my own sessions this way is fundamentally the wrong approach, but it's not obvious what the right one is.

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >