.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Simple WPF ListView Binding Issue

Posted By:      Posted Date: September 21, 2010    Points: 0   Category :WPF

I've uploaded a very simple test project with the issue here: http://www.2shared.com/file/sRVEBh42/KvpTest.html (or here)


The basic problem is, I have a ListView bound to a property on my class. The property is of type ObservableCollection<ObservableKeyValuePair<string, string>>.

I created the ObservableKeyValuePair so I can do two-way binding.


My ListView has 2 columns, Key, and Value. The Value column has a custom DataTemplate which is simply a TextBox, with its Text property setup with a two-way binding (so the user can edit the values of the ObservableCollection<ObservableKeyValuePair<string, string>>.

In my property's setter, I place a breakpoint however it never gets it. The setter of the ObservableKeyValuePair<string, string> is getting hit instead. This seems right, but I need to also propagate that change to the class property my ListView is bound to so I can simply pass the property through to another class and it would contain the changes.

Any ideas how I can achieve this? The sample project is very simple and small if you don't mind downloading it.



View Complete Post

More Related Resource Links

Simple data binding question

Newbie binding question here: is it possible to bind a control in XAML to a StaticResource by passing in the key via a data structure? Basically something like this: <TextBlock Text="{Binding ImageKey}" /> <Image Source="{StaticResource ResourceKey={Binding ImageKey}}" /> <-- doesn't work   The TextBlock binding on the first line works correctly, it extracts the key of the StaticResource from my data structure and displays it correctly. What I'm trying to do is get the Image control to bind to the StaticResource with that name (which happens to be a BitmapImage).      

Command binding issue with using CommandReference and CommandGroup

I'm trying to write an app using the MVVM pattern but I'm running into an command binding issue. I'm trying to bind a button to multiple commands. To do this I'm using the CommandReference class (this is from the MVVM toolkit) and the CommandGroup class (I found this CodeProject). Here is a simplified version of my xaml: <Window.Resources> <c:CommandReference x:Key="TestCommand" Command="{Binding Path=TestCommand}"/> <c:CommandGroup x:Key="TestCommandGroup"> <c:CommandReference Command="{StaticResource TestCommand}"/> <c:CommandReference Command="{StaticResource TestCommand}"/> </c:CommandGroup> </Window.Resources> <Grid> <Button Content="Command Test" Command="{StaticResource TestCommandGroup}"/> </Grid> If I set the DataContext of the window to itself, this works just fine and the TestCommand will execute twice. The problem occurs when I want to follow the MVVM pattern and I set the DataContext of the window to a ViewModel. When I do this the button becomes disabled (I don't see any binding errors in the output window). I tried debugging this to see what was going on. If I set a breakpoint on the PropertyChangedCallback for the Command, I noticed the sequence this gets called is diff

Listview column issue??

Hello.      i have a listview with around 9 column and in that i have column as Address.Now everything works fine....Now suppose lots of character in Address then my css breaks...Is it possible to display few characters of the address followed by .....  ??? i have seen in few site but no clue how to implement...like instead of          Abhishek,House No.30,Middle Lane,Arizon.i want just        Abhishek,House No.30,Middle ......and i would like to implemet mouse hover extender later to display full address but i am not able to implement first part only...Can any one guide me on this??? and i have used this link for my css. http://mattberseth.com/blog/2008/05/modifying_data_with_the_listvi.htmlThanks.

Help - simple data binding

As a newbie I am struggling with the data binding syntax. In the code below I have used a class to create a simple data structure. (I need to be able to fill this from an array which I can do.) For this example I have filled it in directly. However, despite exhaustive searching in the web I cannot find a Visual Basic example showing me how to bind this data source to a Datagrid. I have included in the code the xaml for a basic data grid. Can anynbe help me with the xaml to bind the fields to textboxes? Class MainWindow Public test As String ' Public mage() As Integer = {24, 35, 46, 57} Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded Dim P1 As New myPerson(111, "Bob", 23) Dim P2 As New myPerson(222, "Fred", 34) Dim P3 As New myPerson(333, "Bill", 17) Dim P4 As New myPerson(121, "Alf", 44) Dim st As New SortedList st.Add(P1.name, P1) st.Add(P2.name, P2) st.Add(P3.name, P3) st.Add(P4.name, P4) Dim P As myPerson Dim i As Integer For i = 0 To st.Count - 1 P = CType(st.GetByIndex(i), myPerson) Console.WriteLine("The age of " & P.name & " is " & P.age) Next End Sub End Class Public Class myPerson Public id As Integer Public name As String Public age As In

Binding ListView Control Using MVVM

In this short post I will show you how you can bind the list view control and get the selected value of the list view control using MVVM pattern. For this post I have added one list view control which hold the grid view control in it view and when item is selected in the grid view the selected item is shown at the end of the screen. In the Image 1the selected items are not shown ( only the label fields are shown) but in the Image 2 when user click on any of the item the detail is shown.

Issue with one of simple query

Hi team, I have a issue in the one of my query select   * from Prod3 where pnumber in (select distinct Policy from prod3_excel) order by pnumber This query gives me 8361 records and there are 8419 records in Prod3 how can i get the remaining records in Prod3 that is 58? select * from Prod3 where pnumber not in (select distinct Policy from prod3_excel) order by pnumber why this is not working? Thanks, Eshwar

Binding ISSUE??? How To Bind Dictionary of Dictionary


Hi All I have Problem in binding 

i have object of Dictionary of Dictionary

like this 

ObservableSortedDictionary<string,Dictionary<string,string>>  coll = new ObservableSortedDictionary<string,Dictionary<string,string>>();

Dictionary<string,string> InnerData = new Dictionationry<string,string>():

innderData.add ( "Item1","Data1");

innderData.add ( "Item2","Data2");


i want to bind the inner dictionary (Data) into a GRIDVIEW 

can any one help me to Bind This Object??

ASAP please

INotifyCollectionChanged binding issue


I have an Observable Collection bound to a Datgrid. I want to be able to edit the contents of the Grid and have the bound Collection updated. I understand that I need to make the controls editable and implement INotifyCollectionChanged.


As ever I cannot find a Visual Basic version of this on the web (Express 2010) to unravel so as to understand the syntax. (Below is a working code example how far I have got with this)


I would appreciate any help on this.

Endpoint Binding Issue



      I have a create on wcf service. Which contains one operation contract named getEmployees(); which return me a list<Employee> collection.

     Than i have create a WCF Servive Application and host above WCF Service.

    Now i create a ASP.NET WebApplication and try to call getEmployees() method but i can't.

    I am using WsHttpbinding and configure a Client Endpoint address but still i am having same problem that my client can not able to connect that service.

    Can any one tell me what is the issue?


Ashish Patel, MCTS Software Engineer [Level - 2]

Strange DataGridColumn Binding issue


Hi all,

I'm looking for a way to debug this problem I'm having with binding expressions in my DataGrid.

I've got a data grid that I create columns for on the fly in c# code.  I create DataGridTemplateColumns based on a data class that has an internal dictionary and implements ICustomTypeDescriptor.  I create columns for each of the dictionary's keys.  This all works just dandy, except for one thing.  My output window gets a bunch of these (one for each property):

System.Windows.Data Error: 39 : BindingExpression path error: 'ID' property not found on 'object' ''Object' (HashCode=17704875)'. BindingExpression:Path=ID; DataItem='Object' (HashCode=17704875); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

To debug, I created a converter and removed the Path.  Usually, when I stop the debugger in the converter, the "object" parameter is what I would expect - an instance of my data object.  However, sometimes (as above), the "object" is just an "object" with no further defined type (thus causing this debug output).  I'm a bit at a loss as to why the "object" in the converter is not an instance of my data object. 

Again, all the code seems to work fine.  The data g

ListView issue


Is there any way to bind data to listview using tables?

Lest say I'd like to do more less something like this:

string[] table1 = {"value1", "value2"};

listview1.datasource = table1;

listview databind();

Listview selecteditem binding to textbox causing problems




I have listview and i have binded the listview selected item to a grid's datacontext. The grid contains a text box whose text property is bound to one of the columns in the listview. I have Add, Edit and Delete buttons to manipulate data in the listview.


Whenever i change the selected item in the listview the text in the textbox is changing. Since by default the binding is two way if i edit the data in the textbox it is reflectedi in the listview. But upon clicking on the cancel button the textbox value is not reverted back to old value. The list view itemsource is bound to an object of the class BindingListCollectionView

Code in button click event where BindingDetails is object of calss BindingListCollectionView. But this code does not rollback the changes in the textbox.


btnCancel_Click(object sender, EventArgs E)
  if(IsEdit == true)


I tried the following things.

Trying to get the Text depe

Binding Listview to multiple Objects : ASP.net 3.5

  I am using Object as the data source to my Listview and trying to display data in a Hierarchical manner.  I am not able to figure out how to bind these objects to my listviews. Below pasted is the code. 
I am trying to place Listview inside another listview, inside another listview inorder to display data in a hierarchical manner.  Any help is very much appreciated.
The area with ???? is where i need help.
Thanks in advance
public class AutoElements 
       public class results_dataset
            public List<Claims_history> claimsHistory { get; set; }
            public int count {get; set;}
       public class Claims_history
            public List<Claim> claim { get; set; }
        public class Claim : ClaimType
            public string first_payment_date { get; set; }
Code to extract data from XML :
 public class ClaimsProcessing
      public AutoElements.results_dataset GetResultDataset()
             AutoElements.results_dataset  resultdatasets =
             (from b in query.Desc

Binding Issue


Hey guys,

I'm using the Microsoft Fluent Ribbon in an app I'm writing with a great deal of success...that said; I'm little by little moving my code to MVVM and really liking some of the benefits but at the same time running into some walls in the process...here's my issue:

The MS Fluent Ribbon's Ribbon Control has a SelectedTabIndex property which I'm trying to use in order to bind a TabControl's SelectedIndex property...problem is, the TabControl never changes value when I change tabs on the ribbon.  Apparently the Ribbon control sets its SelectedTabIndex to -1 between switching tab values, and as a result (just guessing) my binding isn't working.  I tried using a FallbackValue but it's had no effect (or doesn't accomplish what I want anyway)...does anyone have any possible suggestions?



If at first you don't succeed, skydiving is definitely not for you!

Binding Datatable to listview in Xaml



  Can any one give me solution for below code.  I know how to bind the datatable to listview in code behind, but  i don't know, how to bind it through XAML. This is my sample code. Please any one help me.

<Window x:Class="ListViewDemo.MainWindow"
Title="MainWindow" Height="350" Width="525">
<DataTemplate x:Key="checkBox">
<CheckBox IsChecked="{Binding Path=Check, Mode=TwoWay}"/>
<ListView Name="lvProcess">
<GridViewColumn Header="Dep_Type" DisplayMemberBinding="{Binding Path=Dep_Type}"/>
<GridViewColumn Header="Check" DisplayMemberBinding="{Binding Path=Check}"/>
<GridViewColumn Header="Depend

Listview Webpart "rootFolder" private property issue in sharepoint 2010


We have used listview webpart to display document library.

The ListViewWebPart contains a private variable called 'rootFolder' that contains the current folder the webpart is displaying.

Below code snippet is used to obtain the value of the private variable contained within the ListViewWebPart.

private static object GetPrivateFieldValue(object obj, string fieldName)


    FieldInfo fi = obj.GetType().GetField(fieldName,

                            System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);


    return fi.GetValue(obj);



However, This is

Strange time issue on simple select statement


Hi, I have a strange time out issue on a simple select statement.
This is my select statement:

Select * from DyGeJournal where ord>=4609635 and Fracsec>=31

The ord and Fracsec is the primary key.
When I ask for the actual excecution plan, he is using a an index seek.
It takes more than 1,5 minutes to get a result back.

When I shrink my database, everyting is running as expected, the query above runs in milliseconds.
After a while (2 weeks) it start agian running very slow.

I have the same logic on other tables, but I don't have the problem on those tables.
What can cause this problem?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend