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

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

Simple binding trouble with a list box

Posted By:      Posted Date: October 26, 2010    Points: 0   Category :WPF

Dear all,

I inherite from a code of a collegue who left the company and I get some troule with a binding in it.

I have a list box binding which is define has follow :

              x:Name="lbScheduler" Grid.Row="0"

As you can see from code above, there is a binding to ItemSource, but in code I could not find any datacontext set. This is the first thing.
Then if I add items to the list box trough a  button dircetly from user interface whihc does lblScheduler.Items.Add(...), then I can see the item correctly display in the listbox.

But during the running of the application, when clicking on a particular buton, some asynchrone process happen which in fact take the list of items in this listbox and then store that list in database.

What it happenning is that right after pressing that button, my list box gets empty and my previous items desapears .

Then right after the button click even, I simply add the following code :

  lbScheduler = _ListBoxSchedulerHelper.

View Complete Post

More Related Resource Links

Binding an array to dropdown list


I have the following string which is a list of urls. How do I get this to work so the url shows for the selection and also is the value?      


allLinks = newAllLinks
        Me.DropDownList1.DataTextField = "Link"
        Me.DropDownList1.DataValueField = "LinkURL"
        Me.DropDownList1.Items.Insert(0, New ListItem(" - Select - ", 0))
        Me.DropDownList1.DataSource = allLinks


 ArgumentNullException: Value cannot be null.
Parameter name: container]
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +121
   System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName, String format) +8

Binding to child list

I have a wpf datagrid that is bound to my business object, Caregivers, which is a custom list of Caregiver.  The Caregiver object contains a child list, ScheduleList, which is a custom list of Schedule. I have successfully bound the datagrid to the Caregivers object using a collectionviewsource and setting the source to my custom object.  I now want to bind the datagrids row details to the child list but I am having trouble.  Here is what I'm trying: My Datagrid is:      <DataGrid Name="DataGridSummary" ItemsSource="{Binding}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" > <DataGridTextColumn Header="Name" Binding="{Binding Name}"/> <DataGrid.RowDetailsTemplate> <DataTemplate> <Border Margin="5" Padding="2" BorderBrush="DimGray" BorderThickness="0" CornerRadius="3"> <DataGrid Name="DataGridDetails" ItemsSource="{Binding ScheduleList}" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray" AutoGenerateColumns="True" CanUserAddRows="False" CanUserDeleteRows="False"> <!--<DataGridTextColumn Header="Clie

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).      

text box binding with Generic list

Hi, I am working in asp.net 3.5 page, where I want to bind a textbox with generic list data. And I have Previous & next button. Which will show the record in textbox. I don't want to go in db again and again.  Is it possible.??? 

Data Binding a DataGrid to a list fetch the same data multiple times

Hi, I'm using DataGrid to show data through data binding. My data are provided in a list. The setup I have is the following: DataGrid "binded" to the default view of my list that implement IList<T> and IList interfaces (MyList<T> : IList<T>, IList, INotifyCollectionChanged)             CollectionViewSource.GetDefaultView(_myList);             // Set the data context             DataContext = view; T: is here my 'business object' that hold the data, called 'MyRow'. Then the columns of the DataGrid are bound to public properties of 'MyRow' object. MyRow class has a public property of type 'object' (public object data[int index]) and first column of datagrid is bound to myRow.data[0], second column is bound to myRow.data[1] and so on.   When the datagrid is displayed, databinding kick in and my data are showed in the control. The issue I'm having is that data fetching is very repetitive even for the same rows. For example for a datagrid with 20 visible rows, the first row is fetched multiple times even if the datagrid is not resized or moved. I put break point inside my list (MyList<T> into This[T] property (public T this[int index]) and i got multiple hits into the property for the same index. Fetc

how to create a List order and unourder a simple Sql Query

A Simple Query Pass to connection String 1 My Query is SELECT a.HD, a.HEAD, a.SH, a.SUBHEAD, a.TRK, a.TRACK, a.TGT, a.TARGET, a.PDC, a.DT_RELEASE, a.STATUS, a.COFROM V_HIERARCHY1 a   2,My Data is HD    HEAD    SH    SUBHEAD    TRK    TRACK    TGT    TARGET    PDC    DT_RELEASE    STATUS    COHR    HR    Rec    Records    Leave    Leave Records    HRL.0002    Quarterly Review    01.07.2010    04.07.2010    Planned    EdlinkHR    HR1    DB    Database    SAL    Salary    DDS.0001    Calculation of Monthly salary    08.08.2010    09.08.2010    WIP    EdlinkHR    HR    Rec    Records    Ind    Induction Records    HRI.0001    Completion of dossiers.    08.07.2010    10.07.2010    WIP    EdlinkHR    HR  

Binding combo box to List box

Hi,      I am fairly new to WPF and i am trying to bind two controls on a page.  What i have is a combo box with one datacontext and a listbox with another.  What I am trying to do is when you select an item in the combobox it will filter the listbox by that selected item.  Below is the xaml for the listbox and the combo box.  the data is the combo box is a code and description.  The code in the list is a key ( the code) and a list of items for that code. Thanks in advance Art <   ComboBox Margin="0.027,23,80.682,0" Name="cboTraitParam"   ToolTip="Select a security Trait to specify for your autobid filter"   Height="22.168" VerticalAlignment="Top" Grid.ColumnSpan="5"   IsSynchronizedWithCurrentItem="True"   ItemsSource="{Binding}"   ItemTemplate="{StaticResource Muni_dropList}"   Grid.Column="1" /> <   ListBox   Name="ParamList" MinWidth="169" SelectionMode="Multiple"   IsSynchronizedWithCurrentItem="True"   ItemsSource="{Binding ElementName=cboTraitParam,   Converter={StaticResource SecurityParamConverter},   Path=SelectedValue }"     Margin="6,111,0,

VB.net - MRU List trouble

Hi, I have a form with a Menu Strip that has an Open and Recent Files menu. When I open a document, it appears in the Recent files menu but disapears when I close the application. How do I keep this information from clearing? Also, how do I keep duplicates from being added to this list? For  example, if I open the same document twice, it appears in the menu twice. Thanks, Imports Excel = Microsoft.Office.Interop.Excel Imports System.IO Imports System.Diagnostics Public Class Form1 Inherits System.Windows.Forms.Form Private Sub OpenToolStripMenuItem_Click(ByVal sender _ As System.Object, _ ByVal e As System.EventArgs) _ Handles OpenToolStripMenuItem.Click Dim ofd As New OpenFileDialog ofd = New System.Windows.Forms.OpenFileDialog() ofd.Filter = "Excel Workbook (*.xlsx)|*.xlsx|" & "All files|*.*" ofd.InitialDirectory = IO.Path.GetDirectoryName("C:\program files\Noxious Weeds Report\Reports\") ofd.FileName = IO.Path.GetFileName("C:\program files\Noxious Weeds Report\Reports\") If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook xlApp = New Excel.ApplicationClass xlWorkBook = xlApp.Workbooks.Open(ofd.FileName) xlApp.Visible = True AddToRecents(ofd.FileName) End If End Sub Private Sub

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 list to form not working with '&' character in list field data

Hi, I have a SharePoint list with a field called Title. I have a form based on this list with the field bound to the form as a label (for workflow to access). Here is the code for the form field. <asp:Label runat="server" id="ff2{$Pos}" text="{@Title}" __designer:bind="{ddwrt:DataBind('u',concat('ff2',$Pos),'Text','','ID',ddwrt:EscapeDelims(string(@ID)),'@Title')}" /> I have a workflow that runs through a form action button which take ff2 (title) and  does other stuff. The problem I have is with records where the value of 'title' contains the '&' character (example ab&cd). Blank is pulled in by the workflow when I get the value of ff2. I am guessing it has to do with the data binding and/or escape (special) characters coming through but I don't know how to fix it. Any help will be greatly appreciated

Trouble using GetListItemFields to pull data from List

First, a summary of what I am trying to do: - I want to use a workflow to create a new site automatically when a user adds a row to the List called "Registry". They choose a title and a Template, I want to take this information and use it in the workflow to create a new site. -So far I am able to create a new site when a row is added, but I cannot incorporate the info that the user entered. Below is the code that I am using inside OnWorkflowActivated to access the "Title" and "Template" fields that the user is entering in the "Registry" List. Any help would be greatly appreciated. Also included is a link to the GetListItemFeilds info page.   http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.getlistitemfields.aspx ***I only have localhost there for privacy reasons***   private void onWorkflowActivated(object sender, ExternalDataEventArgs e) { SPSite site = new SPSite("http://localhost"); SPWeb web = site.OpenWeb(); string itemURL = "/Lists/Registry/AllItems.aspx"; try { string[] itemFields= { "LinkTitle", "Template" }; SPListItem item = web.GetListItemFields(itemURL, itemFields); foreach (string fieldName in itemFields) Console.WriteLine("{0} = {1}", fieldName, item[fieldName]); } catch (NullReferenceException nre) {

Simple WPF ListView Binding Issue


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.



Drop down list not data binding




I am trying to data bind a drop down list inside a formview but for some reason when I click the update button I get the follwoing error message:

'ddl_activity_status' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'ddl_activity_status' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: 'ddl_activity_status' has a SelectedValue which is inval

Drop down list Not Binding on Visible false


Hello i have a textbox1 and drop down list 1

i am filling drop downlist from Sql datasource

and  textbox1.text=Dropdownlist1.SelectedItem.Value.ToString()

all working fine

but if i set dropdownlist1.visible = false  than  textbox1.text = empty string

I need to hide the dropdownlist1 and in the same time i need the selecteditem of dropdownlist   to be in the Textbox1.text

please help me

Problem in binding List<> object to Gridview



We I bind a list<> object to a gridview it calls an error like this:

Error: DataBinding: 'Default2+JobsList' does not contain a property with the name 'JobId'

Hear is my markup Codes:

<asp:GridView ID="GridView1" runat="server" DataKeyNames="JobId" AutoGenerateColumns="False"
                                <asp:BoundField DataField="JobName" .../>
                                <asp:BoundField DataField="JobExplain" .../>
                                <asp:ButtonField CommandName="DeleteJob" .../>

and Code behind:

public struct JobsList
        public int JobId;
        public string JobName, JobExplain;
        public JobsList(int id, string name, string explain)
            JobId = id;
            JobName = name;
            JobExplain = explain;

List<JobsList> list = new List<JobsList>();


list.Add(new JobsList(Approperiate Attributes..));
GridView1.DataSource = list;

wpf Datagrid bound to a Simple List of Long values - not so simple


Somewhere I've lost the plot.  I have a complicated senario, and solved most of it, but still I have one issue that illudes me.  Here goes

User Control has custom Dependancy Properties so that it can bind to it's host window.  One property Route is a string.  The string is actually a comma delimited list of long (BigInt stored values in SQL 2008r2 - pulled through a DataSet, then parsed into a string) ex.  "9,6,12"  Real simple so far.  The user control binds a CollectionViewSource to this string, and uses a custom converter to turn the string into a list(of long)... (or ObservableCollection(of Long), or BindingList(of Long))  The key is the value must be a long, when pulled.  Next enters the DataGrid...

I have a datagrid with 1 column.  Its a DataGridComboBoxColumn.  Its item source is bound to an actual dataset.datatable based CollectionViewSource called RoutingLocations.  A simple list of ID,Abbrev,LocationID.  I bind the DisplayValue to Abbrev.  So I get a nice lookup of the RoutingLocations in the comboBox Column.  Then my list(of Long) gets attached to the DataGrid as it's ItemSource.  End Result  I get 3 rows properly displaying the selected Abbrev for the supplied ID.

Now the problem.  I can not get this datagrid to update the source (it nev

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