Click here to Skip to main content
15,904,653 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 Updated

Data binding 

17 Mar 2024 by Sh.H.
Hi guys Here we have listORG with 3 fields: Idx   ,   Etude   ,   Name ---------------------------------- 1         Etude1      John 2         Etude2      John 3         Etude3      John 4         Etude4      John 5         Etude5      Merry...
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...
16 Mar 2024 by Gerry Schmitz
You don't need an ObservableCollection to "count"; but you can substitute if you want. public class Org { public int Idx; public string Etude; public string Name; } static List _listOrg = new...
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...
7 Jul 2022 by AmirSina Mashayekh
Hello. I'm creating a windows program (Visual Studio - C#) to communicate with AVR MCU using serial port. I want to show available serial ports in a ListBox (or combobox) and update the list immediately when a new device is available or a device is disconnected. Currently I use a "Refresh"...
7 Jul 2022 by joseph wind
public List getCommPorts() { List devices = new List(); string[] ports = SerialPort.GetPortNames(); foreach (string portName in ports) { SerialPort...
14 Aug 2021 by Patrick Skelton
I have a TreeView, which is bound to a hierarchical data structure in my view-model in the usual MVVM manner, something like this: VIEW-MODEL This is constructed when the view (System.Windows.Window) is constructed and set as the DataContext...
3 May 2021 by Member 15145347
I've looked around a bit, but I'm not understanding some of the answers which is why I'm asking here. I'm trying to populate a Treeview with a code-first database as setup with Entity Framework 6. It's an (I think) pretty straightforward...
3 May 2021 by Gerry Schmitz
EF has nothing to do with your "problem". You need to get more familiar how to populate a TreeView. Try loading some data grids first. When that "looks right", you can "advance" to TreeViews. For example, serialize an entity "object graph" to XML...
23 Mar 2021 by ZMirkone
Hello everyone, I've a property in a separate file class with interface Inotifypropertychanged When I modify the source property the target not change. I've tried set Mode="ToWay" but not working What can I do to find out what's wrong? how can...
23 Mar 2021 by ZMirkone
I rewrote all the ViewModels and now it works correctly. Thanks everyone for the answers
15 Feb 2021 by Slow Eddie
I am trying to use an old ComponentOne wijmo grid control to present a List of items on a Web page. It calls for a Data Object to use for the binding. I want to bind it to a Stored procedure I have created in a Microsoft SQL Server 2008R2...
15 Feb 2021 by RickZeeland
Maybe you can find out more here: JavaScript UI Components | UI Tools for Angular, React, Vue | Wijmo[^] They also have some open-source controls on GitHub: GitHub - wijmo/Wijmo-Open: Open Source jQuery UI widgets[^]
20 Jan 2021 by DoingWork
Dear C# WPF Gurus I want to design my WPF Form Like this Image Imgur: WPF User Rights Image[^] Where All column names coming from an Enum names as Role. public enum Roles { Manager, Master, Engineer, Guest } What I have tried: Kindly...
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))) { }
19 Nov 2020 by EmDe-NJ
Quote: I'm trying to use a single Label to display one of the two data fields alternately in Xamarin Forms. Only Label 1 Displaying the binding field (Contact_Name), while second Label which I am trying to use a variable "DisplayField" is not...
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.
17 Nov 2020 by Ken Schneider
I have been searching the Internet for hours and can't figure out how to move a stack panel based on a datatrigger. I'm new to WPF so I don't know if this is the correct way to do what I want. Basically, I want to move views (I was told that...
17 Nov 2020 by Gerry Schmitz
(StackPanel is one of the less flexible panels). Grids can "overlay" content; stack panels can't. To center any control, set the vertical and horizontal alignments to center. Instead of "moving", set the visibility of the controls to...
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...
27 Sep 2020 by YawerIqbal
A couple of questions answered about binding CDS data using Knockout and a few more tips shared
22 Jul 2020 by CTurcotte
Hi,I have been searching around without finding a fix so here I go.I have a Windows with a center that contain a UserControl that will fill the general area of my application.I have a TabControl with multiple TabItem. In each TabItem I have to show different controls including...
22 Jul 2020 by Faisal Fagihi
I had the same problem and here is my solution: - Move your DataGrids to the tabcontrol resource as tiggers. ...
5 Jul 2020 by communicore
a million years later... I'm a vb.net developer so if Ctype/Trycast have different implementations in C# just ignore me!I wonder if it had anything to do with your use of "as" casting (trycast in vb) which obviously returns null and is a better...
5 Jul 2020 by lukeer
Hi folks,in effect, I need to have a dictionary that user can edit and that's stored in app.config.app.config doesn't like generics, it seems. At least I couldn't create a setting with a generic as its type. Not even by typing the fully qualified name instead of searching through the...
4 Jun 2020 by greatoceansoftware
The final solution was to just use ValueConverters to translate the ID into the other Tag properties values and use/display them. A pain, as each property required its own value converter. But since there are only a handful of properties, and...
4 Jun 2020 by greatoceansoftware
So I'm returning to desktop apps after a decade away in non-programming IT roles, and teaching myself C# and WPF. (Don't judge! I see the _reported_ downward trend :-) So here's my problem: I have a hierarchical parent C# object that I'd...
27 Apr 2020 by Volodymyr Kopytin
The project explains MVVM design pattern implementation in JavaScript front-end application.
27 Apr 2020 by Volodymyr Kopytin
Detailed explanation and examples of databind approach to a solution
25 Apr 2020 by Gerry Schmitz
WPF and UWP (not dead) are almost equivalent. If you're talking "objects", WPF and UWP use .NET framework "classes" to instantiate objects; these classes numbering in the thousands. Maybe you're thinking "controls" of which there are enough...
15 Apr 2020 by RossMW
You can define public variables or an object that you want to use in the second form as define from the first form. In your case you could pass an object (datagridrow) or the id the the row from the database or multiple values depending on what...
15 Apr 2020 by ianmark2
I have DataGrid that is populated but an SQL Server database in my MainWindow. I have an event that is fired when the user double clicks on the row to open a new window (Window 1) and populate Textboxes and ComboBoxes with the information from...
11 Apr 2020 by Richard MacCutchan
Of course it converts to server local, since the code runs on the server. You need to capture the client's timezone in the browser code, and pass that to the server, or use the Javascript functions: JavaScript Date Reference[^].
11 Apr 2020 by Member 14192879
when I retrieve it by using .Tolocal() , it returns server local time, not client time. I save my DateTime column after converting it into UTC. solution required for utc time to client local time instead of server local time What I have...
9 Feb 2020 by camibo
Hi, I made a DataSet, and bounded (DataSource/BindningSource) it to a DataGridView. From here the user can type in (double) values which I can later use for my calculations. I've added a button for saving and loading the tables. When i...
3 Dec 2019 by Member 14677113
Well I use microbits with Micropython. Then the idea is to upload it to Mysql database and from there it should be possible to extract from any device, IOS, Android or Windows
3 Dec 2019 by Member 14677113
I would like to know if it is possible to sensor activating a IP camera to snap a picture. The sensor will be activated by a RFID card. the RFID unique ID must then be associated with the picture taken and stored in a database. Thank you for your time. What I have tried: I tried to use...
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....
14 Mar 2019 by Member 14182228
I have implemented this code: dfA = pd.read_csv(args.file,index_col="Full_url",sep=",",engine='c',skipinitialspace=True, encoding='utf-8',dtype={ "City": object,"Country": object,"State": object,"Email": object,"Identifier": object,"Family": object,"Given": object,"Prefix": object,"Suffix":...
12 Jan 2019 by terzasek
Try this. void List(){ SQLConnection.MsSql con = new SQLConnection.MsSql(); System.Data.SqlClient.SqlConnection objConnd = new System.Data.SqlClient.SqlConnection(); System.Data.SqlClient.SqlDataAdapter dtAdapterd = new System.Data.SqlClient.SqlDataAdapter(); ...
12 Jan 2019 by Member 14115523
i write the code to fill combobox with database value. my code is working correctly if this code written on presentation layer. But i want to written this code on data layer. i have 3 project in my solution (UI, BLL, DAL). i want this code in DAL and then call in UI with the help of BLL. how to...
11 Jan 2019 by F-ES Sitecore
Put that code in a function in the data layer but don't do the "foreach", just have that method return "dt". The business layer will just be a single line that will call the function from the data layer and return the result. The presentation layer will then get the datatable from the business...
5 Jan 2019 by Member 2925480
Quote: when using binding checkbox checked (slow and sometimes error at run time) while using "checkstate" works correctly. Is there way to bind checkbox with checked and unchecked only with null represented as unchecked Sub bindingTest(container As Control, sql As String,...
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...
12 Dec 2018 by Member 14006859
I wrote a login form with wpf and entityframework but I have a problem coding. The following error is taken The variable login definition line takes the following error. What I have tried: private void btnVoroud_Click(object sender, RoutedEventArgs e) { IDMS_dbEntities db...
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...
20 Nov 2018 by ilostmyid2
In Visual Studio 2010, when the debugger is told to stop at all exceptions, it does it regardless of whether the exception is handled or not. For example, if you write such a code: try { throw new Exception("test"); } catch { // do nothing } the debugger stops at the line which throws...
20 Nov 2018 by ilostmyid2
In the following code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SQLite; using System.Diagnostics; namespace WindowsFormsApplication1...
20 Nov 2018 by TheBigBearNow
Hello all I’m trying to load a combobox from a static list of a class US_State I made. The list gets populated in my WPF window with all the correct data but my combobox loads if I put ComboboxState.ItemsSource = Get_States; in my window code behind but I thought I could load the combobox by...
20 Nov 2018 by Richard Deeming
public List Get_States = StatesArray.Get_States; WPF data binding only works with properties. You've declared a field, which won't work. If you check the output window in Visual Studio, you'll see a data binding error telling you that the property doesn't exist. Try changing your...
19 Nov 2018 by RmcbainTheThird
Your stack trace has already provided you with the clues you need: C:\Users\hamidi\Documents\Visual Studio 2010\Projects\m_rezaee\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 18 and \WindowsFormsApplication1\List.cs:line 44 Go look at what is happening there. stick in a...
14 Nov 2018 by M.Kamran Asim
Hi 1. Your Us_State class is fine. Found No issue. Why you created AllUSStates public property in Us_State class. its not required. 2. Your static class StatesArray is Fine, but AllFiftyStates method is not required, You can declare states as public property, with public getter and private...
14 Nov 2018 by TheBigBearNow
Hello I tried doing what you said by doing comment and looking at Microsoft. I made a class State with 3 properties (Name, abbreviations, and List using INotifyChange in the properties. Then I made a static class with a List of state and in the constructor adding all 50 states to the List...
7 Nov 2018 by TheBigBearNow
Hello all, I have a question. I have a user object with properties. I have a login screen and when the user logins correctly I pass the user object to the next window. On the top of this next window I would like to display this below with the new line in the control. Should I use a text block or...
7 Nov 2018 by M.Kamran Asim
1. Choice between Label and Textblock depends on requirements. If your data is only text, go for TextBlock. As it is light weight, but if you need some content like image, grid or other complex typed, then label is fine for you. Personally for simple messages, I use textblock with some styling...
7 Nov 2018 by TheBigBearNow
Hello all, I’m not sure why I’m getting a cast error. I can login as an Admin with no problem. I am using inheritance with customer class inheriting properties from user. A admin is just a normal user. Customer only has a few extra properties but before a lil earlier I was able to run my program...
7 Nov 2018 by OriginalGriff
WE can't see the definitions of loginUser and user which are the only explicit casts in that code; we also can't see what type SQLuserAccess.UserLogin returns, or what is in user before you cast that. So run your code in the debugger, and look at exactly what the variables contain. At a guess,...
6 Nov 2018 by #realJSOP
should i be doing this with data binding because this is WPF? Yes.
21 Oct 2018 by VincentSchaw
implement IValueConverter like this public class BoolToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var boo = value != null && (bool)value; return boo ?...
21 Oct 2018 by TheBigBearNow
Hello all, I have been working on figuring out this problem for quite some time now. I am pulling a user object from a database and displaying it in a listview in WPF C#. I can read the data and I have the data separated in columns. I have a Boolean value(bit) in SQL and in my column it displays...
29 Aug 2018 by astrovirgin
Hello All, I am trying to set an error on a datarow which I am filtering out from a datatable and showing that row with error on a grid. What I have tried: The below code is working fine for me - DataRow dr = ds.Tables[0].Rows[0]; //Working dr.SetColumnError("Column1","This is an error"); ...
26 Aug 2018 by WyoMetz
Simple and easy paging of a WPF DataGrid with DataTable and LINQ queries
8 Aug 2018 by Rahul96553
I need a help in my project.Could not get any proper solution as I want. I explain you my scenario here. I am working on WPF project with MVVM pattern, where I have Main Windows screen, on load of Main Windows screen it should be load blank, and only one label is there. On Click of that Label I...
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...
8 Aug 2018 by Gerry Schmitz
Your "view" is buried in a data template of an items control stuck in a stack panel with a bunch of second-fiddle controls. You need to rethink your "view architecture" so that it is more "manageable" in terms of dynamic loading.
19 Jul 2018 by FranzBe
use a BindingList instead of List and a BindingSource and it will work as desired using System.ComponentModel; public partial class Form1 : Form { private Update _currentUpdate; private Project _project; private BindingSource bs; ... private void DoBindings() ...
19 Jul 2018 by Manu Prasad
I am in trouble while working on Databinding in windows form. I have two classes, one is Project and another is Update. Now all project object is having a list of Updates and it is binded to a combobox, but when the user changes selection need to display/bind the properties of Update object to...
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",...
2 Jul 2018 by Member 13895589
I have a databound grideview where I want to color-code the cells in my aspx.vb back end, based on criteria... I started with: If IsDBNull(DataBinder.Eval(e.Row.DataItem, "SwitchPort1")) = True Then e.Row.Cells(3).ForeColor = Drawing.Color.Black Else ...
12 Jun 2018 by Member 13844840
Having trouble binding new data to a D3 BubbleChart. My AJAX call to the API is getting a good JSON reply. I checked the reply and it is getting data in the same format as defined in the hardcoded data used to initially setup the chart. I must be missing something because my chart does not show...
30 May 2018 by Manoj Chamikara
This is My Ajax Call function SelectDocument(DocId) { $.ajax({ url: $("#DocReCall").val(), data: { id: DocId }, }); } This is the Action public ActionResult DocumentReCall(int id) { DocumentsViewModel objViewModel = new...
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...
15 Apr 2018 by Angel Deeyaz
I have a datatable with the following fields: Day Date Room Rate No of Person Amount The data is as follows: Day Date Room No. Room Rate No. of Person Amount 1 4/9/2018 101 900.00 2 1, 800.00 2 4/10/2018 101 900.00 2 1,...
2 Mar 2018 by Member 11302407
I have a form 'sales'. I have added columns manually to dgv. It works fine. But when I tried to bind it with my new class ' receipt ' it showed my the error that Rows cannot be programaticaly added to dgv when data control is bound. I am facing this issue from two days. Anyone who have...
2 Mar 2018 by CHill60
What has this got to do with the title of your post? The problem is clear - you can't do both manually add rows and have the control bound. You can, however, add rows to the dataset ... see the solution on this link Add Rows To Databound DatagridView[^]
23 Sep 2017 by zaibshaki
Everything working fine on 3000 to 4000 images when i am loading 10000 images in listview every error occured ContextSwitchDeadlock occured i am reading all image source using this code BitmapImage myBitmapImage = new BitmapImage(); ...
23 Sep 2017 by Graeme_Grant
ContextSwitchDeadlock is usually an indication that the UI thread was busy for too long. Have you disabled the VirtualStackPanel by mistake or on purpose? Here is a test with 100,000 items and it loads and runs almost instantly. Importantly, the VirtualStackPanel is active. XAML
23 Aug 2017 by prapti.n3
I am calling a code behind function through WEB METHOD. [WebMethod] public static void ws_GetTaskData(string pFromDate) { try { DateTime date = DateTime.ParseExact(pFromDate, "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture); ...
23 Aug 2017 by prapti.n3
With Web Method, we dont get the repeater control. It needs to be re-initialized. So, its better to call the function at page load
22 Aug 2017 by OriginalGriff
This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself. Let me just explain what the error means: You have tried to use a variable, property, or a method return value but it contains null - which...
4 Jul 2017 by Member 10871138
Hi guys I want multiple values from a method in c#. How can I run this scenario? What I have tried: " /> protected void Page_Load(object sender,...
4 Jul 2017 by Bryian Tan
I'm assuming the code has the following variable declaration since you didn't post it. public string Url { get; set; } public string Title1 { get; set; } public string Text { get; set; } The code-behind look OK. Here I think what it should look like based on your current situation. In the...
7 Jun 2017 by Patrick Skelton
I have a Windows WPF application, following a fairly standard MVVM architecture. I am having trouble getting a list of items to respond to changes in the properties they are bound to. Here are some key components that are involved in my problem: public class Contact { public string Name {...
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....
31 May 2017 by Patrick Skelton
I have a validation problem on a WPF window. I have a TextBox, bound to a simple string property in the view-model. I want to ensure the box can never be empty. The TextBox is declared as follows: ...
23 May 2017 by Learn.net37
i have gridview with 12 column and one of the column have 3 value "ex1" "ex2" "ex3" i want if ex1 apppear hide some columns , if ex2 appear hide others columns and so on i try using row roundabout but dint work nothing is hiding What I have tried: protected void...
23 May 2017 by Ajay_Saini
if (e.Row.RowType == DataControlRowType.DataRow) { int index = GetColumnIndexByName(e.Row, "myDataField"); GridView1.Columns[index].Visible = false; }
23 May 2017 by Patrick Skelton
I have what I would consider to be a fairly 'normal' MVVM WPF application. I have a view which uses data-binding to a bunch of properties in the view-model. The properties in the view-model follow the usual pattern: public string Name { get { return _name; } set {...
30 Apr 2017 by Michael_Davies
You get a Null Reference because the .FindName did not find anything, check the returned value before use, if something was returned check it. If nothing is returned and there should be one that is a deeper problem.
30 Apr 2017 by newMemberInTown
Hello, I have a list of string and checkboexes. It has two properties one is the ItemName and one is the CheckedStatus. I want this button to be able to check all the checkboxes. ...
6 Apr 2017 by akosisugar
using vsstudio 2010 (c#, windowsforms).. tblcustomer.. [custno, name, age, gender, addr] the sample code i make works fine but it only search through by [name]. i want to make a search|filter by the selected items in my combobox. items in my combobox is my column names of table.. TIA.. What I...
6 Apr 2017 by Karthik_Mahalingam
try like this string column = comboBox1.Text; string text = textBox1.Text; string filter = string.Format("{0} like '%{1}%'", column, text); this.tblcustomerBindingSource.Filter = filter; Note: Take care of the validations.
15 Mar 2017 by Member 11040029
On my form information about a group is displayed as:1. Group Name:__________ (i/p control: textBox)2. Is Primary: O No O Yes (i/p control: radioButtons)I want to data bind the checked property of the two radio buttons above, with my object.The object is as:public class...
15 Mar 2017 by #realJSOP
CodeProject Article - Binding Radio Buttons to a Single Property[^]
13 Mar 2017 by EmanuelPirovano
Hi everyone,i'm developing , for exercices, a e-commerce site in ASP NET (VB) and i don't understand how i deal the grid view if i use this code to popoulate it :GridView1.DataSource = cmd.ExecuteReader()GridView1.DataBind()I have developed the function of "search item" in my site...
13 Mar 2017 by CHill60
Off topic for this forum I'm afraid - we can't teach you stuff here.Have a look through these CodeProject articles - Search[^] but do come back with any specific problems.
13 Mar 2017 by Graeme_Grant
This may help point you in the right direction: Build a Shopping Cart in ASP.NET[^]
12 Mar 2017 by Onur ERYILMAZ
I bound my datatable to datagridview, every column shows the correct data. But on my Image Column in datagridview does not show the image, instead it shows System.Drawing.Bitmap string.What am I missing?Thanks in advance...What I have tried:My codes are;