Click here to Skip to main content
15,891,253 members
Everything / Data binding

Data binding

data-binding

Great Reads

by The Myth
Databinding examples in WPF for VB.NET.
by Leland Richardson
How to dynamically create item templates on the server-side in ASP.NET.
by Paul_Williams
The difference between ListBox and CheckedListBox DataBinding.
by JayJanarthanan
View a twitter feed in the Windows 8 UI grid - the fast way

Latest Articles

by YawerIqbal
A couple of questions answered about binding CDS data using Knockout and a few more tips shared
by Volodymyr Kopytin
The project explains MVVM design pattern implementation in JavaScript front-end application.
by Volodymyr Kopytin
Detailed explanation and examples of databind approach to a solution
by WyoMetz
Simple and easy paging of a WPF DataGrid with DataTable and LINQ queries

All Articles

Sort by Score

Data binding 

9 Sep 2013 by The Myth
Databinding examples in WPF for VB.NET.
23 Jun 2012 by Leland Richardson
How to dynamically create item templates on the server-side in ASP.NET.
17 Mar 2024 by Graeme_Grant
You would use a CollectionViewSource and use grouping. I assume that you are using WPF. Here is a sample: How to: Sort and Group Data Using a View in XAML - WPF .NET Framework | Microsoft Learn[^]. Hereare some more things that you can do with...
13 Jan 2011 by Simon_Whale
import the excel data and run an outer join queryAccess Outer join query[^]
15 Aug 2011 by Paul_Williams
The difference between ListBox and CheckedListBox DataBinding.
11 Feb 2012 by Wonde Tadesse
Google will give you lots of articles. Perhaps you should search it before asking quesion. Anyways here is what found for you.Using The Silverlight DataGrid[^]
6 Sep 2013 by JayJanarthanan
View a twitter feed in the Windows 8 UI grid - the fast way
27 Apr 2020 by Volodymyr Kopytin
Detailed explanation and examples of databind approach to a solution
27 Apr 2020 by Volodymyr Kopytin
The project explains MVVM design pattern implementation in JavaScript front-end application.
6 Mar 2011 by steini1441
HiI have a winforms app I'm trying to port to WPF. In that I have a datagridview bound to a bindingsource and use BindingSource.Filter = string.Format("Column LIKE '%{0}%'", tb_Filter.Text);in a textchanged event method to let the user filter the datagrid in real time.I'd like to do...
6 Apr 2011 by Henry Minute
When you define your columns set the DataPropertyName property to the required column from the dataset. MSDN Example[^].
16 Jul 2011 by Marc Clifton
Not that I would normally do this, I'm actually just goofing around with .NET's DataGridView...but I have class, Person, that has a List as a property.I'm creating a BindingSource with a DataSource=new List();OK, fine, the grid displays the properties in Person. But...
29 Mar 2012 by Sergey Alexandrovich Kryukov
You need to use Office interop. Start here:http://msdn.microsoft.com/en-us/library/bb726434%28v=office.12%29.aspx[^],http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel%28v=office.14%29.aspx[^].Basically, you start development with "Add Reference". Add a reference from...
5 Jun 2012 by thatraja
Here couple of solutionsGridView - Show headers on empty data source[^]
16 Sep 2013 by Maciej Los
Test it:DECLARE @lessons TABLE(LessonID INT IDENTITY(1,1), LessonName VARCHAR(30))INSERT INTO @lessons (LessonName)SELECT 'lesson A'UNION ALL SELECT 'lesson B'UNION ALL SELECT 'lesson C'UNION ALL SELECT 'lesson D'--UNION ALL SELECT 'lesson E'DECLARE @subject_lesson TABLE...
25 Sep 2013 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
ProblemIt is a typo mistake.SolutionThat is DataSource, not DataSoure.In your code "c" is missing.So. code will be like...protected void Gridview1_PageIndexChanging(object sender, GridViewPageEventArgs e){ GridView1.PageIndex = e.NewPageIndex; GridView1.DataSource =...
5 Nov 2013 by Amitava Bag (Kolkata)
//Alter "btn_FetchName_Click" Event//Alter LinetextBox_EmpName.DataBindings.Add(new Binding("Text", dataSet1.Tables[0], "EmpName", false, DataSourceUpdateMode.OnPropertyChanged));//New LinedataSet1.Tables[0].RowChanged += Form1_RowChanged;//Add New Eventvoid...
3 Mar 2014 by BillWoodruff
Yes, you can sort the values in an Enum for display in a ComboBox alpha-numerically, or any other way you want:// requires Linq// preserve the current ComboBox selectionprivate V currentVName;private void Form1_Load(object sender, EventArgs e){ var vAry =...
8 Aug 2018 by Graeme_Grant
There are multiple questions above. To keep it simple, I will try and answer the part about navigation in the MainWindow using the MVVM Design Pattern. I'm sure that there are a lot of people have different ideas on what is the best solution and there are many libraries that implement a variety...
2 Oct 2019 by Maciej Los
Wel... Start here: Ready-to-use serial port enumeration list box[^] For further details, please see: SerialPort.GetPortNames Method (System.IO.Ports) | Microsoft Docs[^] [EDIT] There's no guarantee that SerialPort.GetPortNames method will return the names of ports. But, there's work-around....
12 Mar 2024 by OriginalGriff
There are problems here with what you want to do: you can't use a single ObservableCollection for two different lists, and while you could put all the items from both into a weakly typed ObservableCollection and cast them appropriately when you...
13 Jan 2011 by @nuraGGupta@
AFAIK about WPF, there is not much difference in normal Datagrid binding (asp.net) and WPF Datagrid binding when you are doing it on server side. So I hope this link will be useful to you.Binding an ArrayList with DataGrid Control[^]Anurag
28 Jan 2011 by Henry Minute
Amongst all the tags you applied to your question you forgot to include one for the type of Database (SQL Server, Access, MySQL, ????).Still, one suggestion. If your database allows default values for columns setting that to 0 or any sensible number for your scenario might resolve the...
6 Mar 2011 by Henry Minute
I don't know how helpful this is going to be to you, since you seem to already have the basics, but I found this article[^] yesterday.
9 Mar 2011 by phil2415
Hi all,I have a problem with binding a reorder list, the control that is part of the AJAX Control Toolkit. I hope you can help because I've spent hours developing it!I created the list and had it working perfectly, with insert, edit and delete commands, as well as reordering all...
16 Mar 2011 by #realJSOP
Are you trying to format the text before it's displayed? If so, you're going about it the wrong way. You need to handle the oBinding_Format event:Private Sub oBinding_Format(ByVal sender As Object, ByVal e As System.Windows.Forms.ConvertEventArgs) Handles oBinding.Format e.Value =...
6 Apr 2011 by Toniyo Jackson
Goto Datagridview Properties --> Columns.Then you will get small window. In the right side you can see 'DataPropertyName' in column properties.For each column set the database column name.Then give AutoGenerateColumns = false.
8 Apr 2011 by Amund Gjersøe
HiI'm focusing on "The user should be able to change the selected item in FooContainer by changing the selection in the DataGridView."The following solution lets the user select items by clicking the cell, and the following event sets the according item in the bound data collection to...
8 May 2011 by Keith Barrow
It took me a little while to spot what is happening. The reason for your problem is you are changing the reference to the CurrentCustomer on the Customers object in a way that won't re-bind the UI. To see what I mean:Have Customers implement the INotifyProperyChanged Interface. I normally do...
1 Jun 2011 by Marrakech
HiTo Do this:1. In Windows Forms designer go to combobox properties.2. Find datasource property and expand it3. Click "Add new Project datasource".4. In the wizard select Object and then Next.5. Select Person class in the tree ( if you does not have it try to build project with...
1 Jun 2011 by Wayne Gaylard
Try this wayList person = new List() { new Person(){Name="Anna", Birthday=new DateTime(2006, 10, 01), Age=12}, new Person(){Name="Ben", Birthday=new DateTime(2006, 11, 02), Age=13}, new Person(){Name="Cora",...
15 Jun 2011 by Manish V Mahajan
Hi,I'm new to WPF and C#. In my XAML file, I have a simple Rectangle, where I am binding the width and the fill color:When my program loads, I am reading the width and the color from a...
15 Jun 2011 by isaks
The reason you get a thread error when you update your brush is because all graphical objects are expecting a single threaded always.Now fortunately for you in this case, there is an exception and that is the Freezable class which all brushes inherit from. Those can, after they have been...
28 Jul 2011 by Tajuddin_HYD
Hi,You can use the following query to get the last rowSELECT Top 1 id FROM table_department WHERE departmet='abc' ORDER BY id desc
29 Aug 2011 by Abhinav S
Use the SelectedIndex property[^].Once you have the value you have selected, fetch the values related to this index (the ones that you want to show in textboxes).These will need to be fetched from the database or a temporary memory store.Display these values.
14 Sep 2011 by theHollow
HiI may have misunderstood the question. But you should concider using ObservableCollection instead of List when presenting data to the UI, because the ObservableCollection also implements the notification properties notifying changes in the list.Hope it helps :-)
31 Oct 2011 by Espen Harlinn
Have a look at:WPF DataGrid Practical Examples[^]Best regardsEspen Harlinn
20 Nov 2011 by Sergey Alexandrovich Kryukov
Sorry, this is complete gibberish, see http://en.wikipedia.org/wiki/Gibberish[^].It looks like you don't know what programming does. Why do you think you can change the behavior of program by deleting any lines of code? Delete from what code? Do you know that a program is compiled, so it's...
1 Feb 2012 by Catalin Serafimescu
Have you tried Binding::Format and Binding::Parse ? http://msdn.microsoft.com/en-US/library/system.windows.forms.binding_members(v=vs.80).aspx[^]
11 Feb 2012 by RDBurmon
You can use below code : string myConnection = conn.ConnectionString.ToString();//"Data Source=MDT765;Initial Catalog=TST;User Id=user;Password=user@123;"; SqlDataAdapter sqlcom0 = new SqlDataAdapter("SELECT Id,Name,Pos,Loc FROM Employee", myConnection); ...
1 Mar 2012 by Sunasara Imdadhusen
Hi All,Now i resolved issue using following code. I have replaced following linetxtTextBox.SetBinding(TextBox.VisibilityProperty, new Binding("Redactable") { Source = this, Converter = new BoolToVisibilityConverterReverse() });with this.MapBinding(RestrictedControl.ValueProperty,...
4 Jun 2012 by Arjun YK
Well This Link Solved My Problem http://csharp-guide.blogspot.in/2012/04/capture-button-click-events-in-datalist.html[^]
8 Jul 2012 by _Amy
Hi,After binding your datalist just you need to call the given function below.private void fnChangeLinkStyle(){ foreach (DataListItem dli in DataList1.Items) { if (dli.ItemType == ListItemType.Item || dli.ItemType == ListItemType.AlternatingItem) { ...
30 Aug 2012 by vijay bisht
dim ds as new dataset dim qry as string = "select * from tabletemp"dim command as sqlcommand = new sqlcommand(qry,connection)dim da as sqldataadapter = new sqldataadapter)command)da.fill(ds,"tabletemp")dim datevariable as stringdatevariable =...
16 Oct 2012 by Clifford Nelson
Unfortunately there is no SelectedItem read/write dependency property for WPF. You can create a behaviour to get around this (http://stackoverflow.com/questions/1000040/selecteditem-in-a-wpf-treeview[^]), or use code behind for the SelectedItemChanged. Ideally you should have a view model...
22 Oct 2012 by Bhushan Shah1988
You can use Server Side event TextChanged of Textbox.
28 Oct 2012 by Cagri Kaynar
try this code lbItemsList.BeginUpdate(); lbItemsList.DataSource = null; lbItemsList.DataSource = shoppingBasket.OrderItems; lbItemsList.EndUpdate();
12 Nov 2012 by Andreas Gieriet
How about...//create a datasource for TreeView or GridView using the xml document in memory.XmlDataSource xmlds = new XmlDataSource();xmlds.Data=xdoc.ToString();xmlsd.ID="SomeGloballyUniqueNameForThisDataSource"; // e.g. "Products"...See also MSDN: XmlDataSource.Data...
28 Dec 2012 by db7uk
Unfortunately yes. If you do not use something like Notify Property Weaver[^] you will need to raise the notify on each property change.If you do not go down the automated route, I would really recommend setting your property value and then raising the changed event on the property setter...
30 Jan 2013 by Aarti Meswania
in button click event...if condition should be like belowif AnswerTextbox.Text.ToLower() = yourAnswer.Text.ToLower() thenToLower() will convert both textbox values in lower case and then it will compare themHappy Coding!:)
11 Apr 2013 by Francisco T. Chavez
The issue I see in you code is that you are trying to bind the ItemsSource to use the AvosEntries of your DataContext (which happens to be the collection pointed to by your AvosEntries property). Basically, you are trying to use the AvosEntries property of the AvosEntries collection. I see...
14 Apr 2013 by Shmuel Zang
In btnBrowse_Click you set the value of CurrentArticle but the DataContext still keeps the old value...You can set the DataContext too: private void btnBrowse_Click(object sender, RoutedEventArgs e) { //logic for openfiledialog //strFilePath is...
23 Apr 2013 by Sandeep Mewara
I have found that specific questions related to 3rd party is answered more quickly and accurately at respective forums.Posting such issues about a 3rd party control (Infragistics here) Forum would be more useful, here: Infragistic Forums[^]
27 Jun 2013 by Jason Gleim
I'm going to expand my comment...ItemSource is meant to be bound to an object that supports property change notification. What you should do is implement INotifyPropertyChanged on your class (I'm assuming the code-behind for that page) then add a property for each ItemSource:public...
27 Jun 2013 by kpolecastro
Imagine the items in triplicate for the different listboxes Source="{Binding Source={x:Static Application.Current}, Path=CurrentList}" x:Key="CurrentList" /> > ...
27 Jun 2013 by kpolecastro
To anyone that can help or show me a better way. I have tried to do this with an observable collection, a list based on a custom class, global/non-global collections, using the listbox's itemssource, synclocking, and finally emptying and manually entering in items.It tends to work fine, but...
27 Jun 2013 by Pheonyx
I've seen similar issues, and managed to fix them by re-working the code.The first change I would make would be with these:Try For I = Me.ParentListbox.Items.Count - 1 To 0 Step -1 Me.ParentListbox.Items.RemoveAt(I) NextCatchEnd TryTry For I =...
19 Sep 2013 by Matt T Heffron
When the XAML is processed/executed, it is instantiating all of the classes.The ... is instantiated, so is the ...and so is the !!
23 Oct 2013 by Member 10321925
I have 3 TextBoxes (Id,Name and Salary)Id and salary should be integers and Name is only charecters.I need validations for my TextBox as i enter wrong charecters or integers it should show error and also can i do it this in only xaml without codebehind ? I'm new to Wpf and validation please help...
17 Feb 2014 by Matt T Heffron
You can't do this directly.The Window and SecondControl are two different contexts (WPF XAML NameScope) and the ElementName is limited by NameScope."You can refer to elements in code only if they are registered to the appropriate NameScope" MSDN: Binding.ElementName[^]So, I see two...
4 Jun 2014 by NeonMika
So, I found a solution for my question here: http://stackoverflow.com/questions/1152128/wpf-databind-to-a-stackpanel-using-datatemplates[^]Replacing the StackPanel with a ContentPresenter and instead of DataContext using the Content property worked for me.Probably it will help someone...
13 Aug 2014 by OriginalGriff
The solution is simple: don't try to load any UI element with that many items.Think about it: how you like to use that software and try to find the one selection you need to use in a list of 200,000 other ones? Every day? Probably several times every day?If I tried that, my users would...
17 Sep 2014 by Richard Deeming
You'll get better results if you bind the list in the Init event of the control, rather than the page.protected void ddlCustomers_Init(object sender, EventArgs e){ var ddl = (DropDownList)sender; ddl.DataSource = SystemData.GetAllCustomers(); ddl.DataTextField =...
8 Nov 2014 by Manas Bhardwaj
Swap the dictionary format. Or I misunderstood the question?Dictionary AccountType = new Dictionary { {0, "no type"}, {1, "basic"}, {2, "derived"} };combo.DataSource = new BindingSource(AccountType, null);combo.DisplayMember =...
22 Nov 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
For that, you should bind the Units DropDown inside the SelectedIndexChanged Event of the Products DropDown.
20 Aug 2015 by Wendelius
Not sure if I understand the question correctly, but you should call OnPropertyChanged only when the value of the property is actually changed and preferably inside the setter of a property and only for that property.Based on your code you call OnPropertyChanged for the FirstName property...
13 Mar 2017 by Graeme_Grant
This may help point you in the right direction: Build a Shopping Cart in ASP.NET[^]
31 May 2017 by J. Calhoun
I personally use an event trigger on the event lost focus to do a string.empty check. If the string is empty then I replace it with my default string. I also use the command property to fire the validation in the view model, or you can extend a behavior in the textbox control to do this as well....
15 Apr 2018 by Maciej Los
Check this: Dim dt As DataTable = New DataTable() dt.Columns.AddRange({New DataColumn("Day", GetType(Int32)), _ New DataColumn("Date", GetType(DateTime)), _ New DataColumn("Room No.", GetType(Int32)), _ New DataColumn("Room Rate", GetType(Double)), _ New DataColumn("No. of...
2 Jul 2018 by Maciej Los
If i understand you well... i'd suggest to simplify this by using Dictionary class[^]. See: 'define "color translator" ;) Dim ColorTranslator As Dictionary(Of String, Drawing.Color) = New Dictionary(Of String, Drawing.Color) 'add keys and values With ColorTranslator .Add("-1",...
12 Dec 2018 by OriginalGriff
Look at your error message: Exception thrown: 'System.Data.Entity.Core.EntityCommandCompilationException' in EntityFramework.SqlServer.dll Additional information: An error occurred while preparing the command definition. See the inner exception for details. So use the debugger, and look at the...
5 Jan 2019 by Maciej Los
Well, true is true, false is false and null is null. What this meant to you? You have to handle it. But... please read it before: Nullable Value Types (Visual Basic) | Microsoft Docs[^] Databinding and Nullable types in WinForms.NET[^] How to achieve that? Please, see: Bound CheckBoxes when...
21 Oct 2020 by Member 13707743
I'm using wpf c# and Entity Framework I have a DataGrid on that show data from database when users click on datagrid that row will show items in ComboBox (Load on of columns in combobox) but problem is combobox doesn't show Normal list...
19 Nov 2020 by Gerry Schmitz
When you create your "item source collection", assign either the VALUE of "email" OR "address" to the "display field" (column), and just display what's in that column. Easier than what you're trying to do.
20 Jan 2021 by Christian Graus
Once you add a datagrid, you can label the columns anyway you want and it's possible to foreach over an enum foreach (Suit suit in (Suit[]) Enum.GetValues(typeof(Suit))) { }
12 Jan 2011 by Ashy-G
Hi, I would like to know how to populate a WPF DataGrid with a list of objects without using data binding and manually defining columns in DataGrid. Also how can you populating a DataGrid from a MySQL or SQL database without using data binding? Is there a way to click on a DataGrid row...
13 Jan 2011 by MaulikDusara
I have two files (1) Access (2) Excel in both there are many records available. There are more than 50000 and I want to find out how many new records are not available in Access which are in Excel. :confused: both files structure are not the same. There is just one identical column in both...
18 Jan 2011 by Henry Minute
If you mean that you want to provide the contents of the ComboBox dropdown then you need to use the Items property. myComboBox.Items.Add("Some Text"); myComboBox.Items.Add("Some More Text");or string[] items = new string[] { "Some Text", "Some More Text" }; ...
18 Jan 2011 by jerrykid
Hi astika,ComboBox will display Text property when you select an item. And SelectedValue, SelectedItem will have value(s) when only if you set DataSource, DisplayMember, ValueMember property. Please try:cbo.DataSource = dataSet;//Or dataTablecbo.DisplayMember =...
24 Jan 2011 by NeRane
I have two list boxes related to each other on the same form. The first is bound to a IEnumberable of MembershipDataViewModel Objects (Essentially Users). I have a fancy Data Template that shows the user, email and whether or not it has been modified and all, it works great. However, i have a...
28 Jan 2011 by Sander Rossel
Hello,I am currently experimenting with databinding.Now there is one problem I cannot seem to fix.I have a DataSet with a DataTable. In this DataTable I have a Column which does not allow null values.Now I have a BindingSource which has the DataSet as its DataSource and the DataTable...
29 Jan 2011 by [DK]KiloDunse
Hi.When I use this select in a entitydatasource.CommandText:CommandText="SELECT it.[LiteratureID], it.[ReleaseDate], it.[Title], it.[Text], it.[ThreadID], it.[Added], (SELECT COUNT(fp.PostID) FROM ForumPosts AS fp WHERE fp.ThreadID = it.[ThreadID] AND fp.Status = 1) AS Posts FROM...
29 Jan 2011 by [DK]KiloDunse
Found a solution.Adding VALUE to the nested SELECT returned a list of Int32 insted.Binding like this, returned the value:Comments=''
30 Jan 2011 by sathya.spidy
Hi friends, I have a doubt to display the content of the tables in matrix format. I have three different tables (1)Day Order (In this i have the day order details) DayOrder Id ...
31 Jan 2011 by Amit Kumar Tiwari
It is simple if you try. First design a query to fetch all values. Then customize the Gridview using template and display the data.
9 Feb 2011 by Siavash Mortazavi
Hi dear experts ;)In my WPF app, I have a class called Employee with 2 fields: FirstName, LastName.In my view model, I have two bindable properties:ObservableCollection Employees;int CurrentIndex;I want to bind a TextBlock on my view to the FirstName field of current...
9 Feb 2011 by Nish Nishant
It would be far more easier to add a new property to your view-model called CurrentEmployee which returns Employees[CurrentIndex].
9 Feb 2011 by Siavash Mortazavi
Thanks Nishant :) You're right;I didn't want to maintain an extra reference for that; but it seems it's unavoidable.Cheers,Siavash
8 Mar 2011 by se.nishant
i want data from a label of data list in asp.neti created a template of data list and use a labelafter binding data in label i want to access the value of label
8 Mar 2011 by Niranjankr
You can try :string id=((lable)Datalis1.findcontrol["lable1"]).Text;
8 Mar 2011 by m@dhu
foreach (DataListItem dli in DataList1.Items) { Label Label1 = dli.FindControl("Label1") as Label; string lblValue=Label1.Text;}//In Datalist events.Label Label1 = e.Item.FindControl("Label1") as Label;//can get the value in string...
10 Mar 2011 by Dave Kreskowiak
I suggest reading the documentation on AcceptChanges and Update. Update writes the dirty records in the DataSet/DataTable back to the database. AcceptChanges tells the DataSet/DataTable that the changes that were made are now the current state of the records. The two operations are completely...
6 Apr 2011 by garfield185
Hi, I'm trying to fill a DataGridView with the data taken from a Select.I don't want the columns to be created automatically, I already defined some with styles and all that stuff. However, when defining the datasource, my DataGridView shows the expected number of rows, but empty.If I...
6 Apr 2011 by Mahendra.p25
try this its an example and use dataField same as you database table columns
7 Apr 2011 by lukeer
Hi experts,let's assume this codeusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Test_DataBinding{ public partial class Form1 : Form { ...
12 Apr 2011 by mridul samadder
I am using a datalist control to show per user comments.there is a comment textbox for showing comment per user in itemtemplate.now when i will click the edit command button i want that comment textbox will be enabled to edit comment text and when update is clicked that user comment will be...
13 Apr 2011 by mridul samadder
Thanks mkgoudactually i was right with same codes in the link but was confused