I think the problem is that your ListBox has no way of differentiating between the two "Anand" records. It sees them as the same thing. Try creating and populating a class that inherits from ObservableCollection. Then bind the ListBox to the collection. This way, each ListItem will be unique.
D Dubya
Posts
-
selection Problem in listbox when contains ,More than one same data [modified] -
How to update combo box selection before promptHi all, I have a combo box in my WPF application that displays a confirmation dialog (
MessageBox.Show()
) when certain items are clicked. Ie. I have the following options - Pending (default selection) - Completed - For Review When the "For Review" option is selected, I display the confirmation dialog. My problem is that the combo box isn't updated prior to the dialog being displayed. So, even though "For Review" was selected and the Selection_Changed event is firing, the combo box shows "Pending" while the dialog is being displayed. I've tried someDoEvents
loops and even tried changing the combo box selection programatically prior to showing the dialog, all to no avail. Any ideas? -
How to Maintain Copy of SortDescriptionCollection After DataGrid RebindHi all, I'm using a DataGrid from the WPFToolkit v3.5 and I'm trying to reapply a user-defined sort following a refresh of the DataGrid. To do this, I'm trying to store the DataGrid's
SortDescriptionCollection
in a local variable and then re-add the SortDescriptions once the DataGrid has been rebound. My problem is that the local variable seems to be more of a pointer to thedtg.Items.SortDescriptions
collection rather than a copy and is reset back to zero once the DataGrid is rebound. Here's the code:1. Dim complexSortDesc = Me.dtgComplexQueue.Items.SortDescriptions
2. Dim numComplex As Integer = PopulateComplex().Count
3. ApplyCustomSort(dtgComplexQueue, complexSortDesc)
4. UpdateQueueTitle(numComplex)When line #1 is completed, I have a count of 2 SortDescription objects in
complexSortDesc
. After line #2 has run,complexSortDesc
has a count of zero. Here's the PopulateComplex fn:Private Function PopulateComplex() As Requests
Dim complexRequests = New Requests(QueueType.Complex)
complexRequests.Sort(New DefaultSortByImportDateAndSurname)
dtgComplexQueue.ItemsSource = New TriageMenuDataMembers(complexRequests)
Return complexRequests
End FunctionHow can I get a copy of the
SortDescriptionCollection
so that the collection exists after the DataGrid has been rebound? I don't seem to have this problem in other areas of my app so I'm thinking it has something to do with the PopulateComplex fn..? :confused: Thanks -
XML Import Failing on XMLDocument.Load: Unexpected end of file has occurred.Hi all, I'm attempting to load an xml document from an XML column in MSSQL 2008, into an XmlDocument (see code below). Sometimes the code will break at the <b>xdoc.Load(xr)</b> line with the error "Unexpected end of file and occurred". After breaking, the XmlReader has a value of "None". While researching the problem, I saw posts that referred to a 4Kb limit on StreamReaders and figured this may be related somehow. So I cut down the size of my document (to around 4Kb) and everything worked fine. On average, the XML documents I'm importing from the database are 20Kb and thanks to validation on INSERT by MSSQL, we can assume(?) the document is well-formed. Does anyone know how to get 'large' amounts of XML from the database into my XmlDocument?
Dim xr As XmlReader = ExportAdapter.GetEditedCheckXML(chkId)
Dim xdoc As New XmlDocument
xdoc.Load(xr)Here's the GetEditedCheck fn:
Public Shared Function GetEditedCheckXML(ByVal checkId As Integer) As XmlReader Dim conn As SqlConnection = New SqlConnection(CONNECTION\_STRING) Dim comm As New SqlCommand("PS\_GetModifiedXmlByCheckId", conn) Dim adap As New SqlDataAdapter comm.CommandType = CommandType.StoredProcedure comm.Parameters.Add("@checkId", SqlDbType.Int).Value = CInt(checkId) conn.Open() Dim xml = comm.ExecuteXmlReader() xml.Read() conn.Close() Return xml End Function
-
Disabling MenuItem IconGreat!.. Works like a charm. Do I need to use DynamicResource because the 'inner' MenuItems aren't compiled at the same time as the rest of my XAML?
-
Disabling MenuItem IconHi all, For the last couple of days I've been try to disable the MenuItem.Icon image when the MenuItem itself becomes disabled. I've implemented Style Triggers for my Toolbar icons but I can't seem to get them to work with the MenuItem icons. This is my current style definition (in my Main Menu uc):
<UserControl.Resources>
<!-- The following style causes the toolbar buttons to become dimmed when they are disabled -->
<Style TargetType="{x:Type Image}" x:Key="menuImageStyle">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type MenuItem}, AncestorLevel=1}, Path=IsEnabled}" Value="False">
<Setter Property="Opacity" Value="0.4" />
</DataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>With this as the MenuItem itself:
<Grid>
<Menu Height="22" Name="mnuMainMenu">
<MenuItem Name="itmFile" Header="{x:Static r:ucMainMenu.itmFile}">
<MenuItem Name="itmSave" Header="{x:Static r:ucMainMenu.itmSave}" Command="ApplicationCommands.Save" InputGestureText="Ctrl+S">
<MenuItem.Icon>
<Image Name="imgSave" Source="/SCPS;component/Icons/save.ico" Height="16" Style="{StaticResource menuImageStyle}" />
</MenuItem.Icon>
</MenuItem>
</MenuItem>
</Menu>
</Grid>I found a blog posting that recommended moving farther up the element tree by using UIElement instead of MenuItem as the Ancestor Type, but that didn't work either. I did notice the following being displayed in the Output window:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.MenuItem', AncestorLevel='1''. BindingExpression:Path=IsEnabled; DataItem=null; target element is 'Image' (Name='imgSave'); target property is 'NoTarget' (type 'Object')
Also, in trying to debug this issue, I got myself a copy of Snoop and noticed that the root element of a Context Menu is not the ApplicationRoot... Unsure as to whether or not this relates to my problem... Any thoughts?