Updating continuously listview with data from an ObservableCollection<T> [closed] - c#

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I need to bind a list an observablecollection to the listview. This listview must be updated each time when data changes in the observablecollection.
For now I can only bind one element of the observablecollection to the listview at the same time, whenever the second one is bound, it will cover the last one.
My purpose is to bind all the data which are created by calling LoadAlarms() in to the listview .
These are my XAML codes:
my Alarms class
My codes in viewmodel
the fist time LoadAlarms are called, I have the result
The second time LoadAlarms are called,I have the result
I would like to display these both results to the listview but I can only see the last update.

Your class Alarms must be inherited from NotificationObject and its properties must do RaisePropertyChanged whenever they change.
ObservableCollection should be allocated once and then only use add, remove etc.
Why do you have a ListView that contains a grid that contains a grid that contains another ListView? What are you trying to do if I may ask.
Hope this helps..

Each time you call LoadAlarm() you overwrite your observable collection with a new one.
Call AlarmList = new ObservableCollection<Alarms>() only once for example in a constructor.

Related

How to make ListView look like flowing? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have a ListView and it adds an item per second dynamically in C# WPF. Since I feel it will get stuck after thousands of items I clear it when it holds more than 100 items.
But then it doesn't look good and disappears all of a sudden. Is there a way by code to make it look like items continuously flowing? How can I delete a particular item when it reaches to 100 items so the items would look like flowing?
Before adding new items check how many are already there and remove some (the oldest ones in the beginning) to stay under limit:
int limit = 100;
while(myListView.Items.Count >= limit)
{
myListView.Items.RemoveAt(0);
}
myListView.Items.Add("new item");

How do we clear previous page data on SelectedIndexChanged Event..? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have aspx page.having an issue is that if we select first time option from drop down value gets appears on the page.but when we select second time option from drop down still previous data getting appears. how do i clear all the previous data after drop-down SelectedIndexChanged Event..?
As you have not provided the code when i'm writing this answer. In Asp.net u can achieve this by using jquery. I'm using club dropdown list with ID clubs as an example. This event will bind to the list and will keep on updating selected variable when the selectedIndex change. Then you can simply pass the selected variable value to lets say a span element with id spanClub
$(document).ready(() => {
$('#Clubs').change(() => {
let selected = $('#Clubs :selected').text();
$('#spanClub').text(selected);
});
});

Who uses NotifyCollectionChangedEventArgs' features? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
This is a follow-up to my question, How does WPF handle CollectionChanged events for custom collections?.
According to Alex.Wei's answer (and the source code of IndexedEnumerable) WPF ignores the specifics of the NotifyCollectionChangedEventArgs (e.g. Action) and always reacts the same, ultimately as if Action == Reset.
So my questions: Who uses NotifyCollectionChangedEventArgs' features and, if I raise the event manually (for a custom class) does it make sense to specifiy the details (if they are never evaluated)? Also, why does WPF behave like this - isn't this a potential performance killer?
I am sorry if I didn't make things clear in last anwser. Actually, WPF behaves according to specifics of the NotifyCollectionChangedEventArgs like it means to be, and IndexedEnumerable just a tool that let CollectionView or other componets of WPF access to the source collections that didn't implement IList throngh an index easily. For example, after you bind a collection to ItemsControl.ItemsSource, the things in below will happen.
ItemsControl will specify the collection as the source of its Items property.
Items property which is an ItemCollection will obtain a CollectionView by calling CollectionViewSource.GetDefaultCollectionView method.
The view will try to subscribe CollectionChanged event of the source collection and act accordingly.
ItemCollection will also subscribe CollectionChanged event of the view and act accordingly.
And also, ItemsControl subscribe CollectionChanged event of the Items and act accordingly form the beginning.
So, the answer to you questions is that a lot of WPF classes are using NotifyCollectionChangedEventArgs' features and you definitely need to riase CollectionChanged event correctly by providing all the details whatever you collection was implemented IList or not.
My experience is that WPF is going to raise an exception if you provide wrong indices or multiple elements in an Add or Remove action.
Apart from that, there is a range of frameworks (NMF Expressions, BindableLINQ, ContinuousLinq, Obtics) that make use of these CollectionChanged events in order to implement INotifyCollectionChanged on queries. These frameworks will heavily rely on the details that you put in the event, despite you can of course always resort to a reset event.
Take a look on my ObservableComputations library. That library uses NotifyCollectionChangedEventArgs very widely.

Hiding drop down values without affecting functionality [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
In my application I am trying to hide the values in my drop down list while it carries out the required functionality. As shown below you can see the drop down showing a value. The values are being pulled from a database.
When selected it would show the values below:
I would prefer if the values are not shown. Meaning I would want the dropdown values to not be shown but still carry out the fill operation as shown above.
So to explain more clearly, My comboBox which contains the value "123456789" would pass the values "P10434" and "Jev Pharma" to the respective textBoxes below respectively.Instead of showing my dropdown values while typing(auto suggest currently does this) I would instead want the dropdown list to not suggest any values at all. Meaning once I type "1234567..." it would not show any values int he comboBox but rather accept the info being typed in and pass the corresponding values from the database to the texboxes below.
I have tried changing the properties of the comboBox by removing append and suggest but the functionality is different. It no longer fills the data but instead just allows typing of a value. I am not sure how to approach this. Any suggestions?
Set the properties as follows:
comboBox1.AutoCompleteMode = AutoCompleteMode.Append;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
comboBox1.DropDownStyle = ComboBoxStyle.DropDown;
This will append the suggestions when typing without showing the list.
You can handle the appropriate event per your requirement to fill your textboxes.

Binding checkbox in WPF by output of a method in a ListView [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
im making a small desktop application using WPF.
I have a view that includes a listview with items, every element binds fine by the itemssource property and a {binding name} for instance.
However each listview item must have a checkbox. Whether the checkbox is checked is dependent on whether or not the item exist in a different list, meaning that i cant bind it by the model/datacontext. Is it possible to bind the isChecked property of the output of a method from the code-behind file? or how can i do this?
You say you have a listview and its itemssource property is bound to the viewmodel's collection.
If so you should extend the object which instances are in that collection with a bool property. This property shall determines whether the instances is in the other list you mentioned and that property can be bound to the checkbox isChecked property.
Or you can do some nasty things in the code-behind file (iterate throug the listview's items and check whether the item is in the other list and look up for the item's checkbox and check it accordingly) but I strongly recommend not to do that.
Your question is not very clear but if i understand correctly, you can try to use a checkedListBox. It can contains a list of checkboxes and you can iterate through it:
for (int i = 0; i < checkedListBox1.Items.Count; i++) {
if(....) {
//here you can write your if statement or call a method whose return type is bool
checkedListBox1.SetItemChecked(i, true);
}
}
If i understand correctly what you are trying to do, you can use ValueConverter on the isChecked binding.
On that method you can do a compare or test of the parameter exists in other lists.
No need to break the mvvm pattern for that
iValueConverter usage and tutorial:
Value conversion with IValueConverter

Categories

Resources