Hi everybody.
I'm building a search - function in Xamarin (see code below):
I'm filling a Listview with data ( public async void FillSearchList()).
When the user writes in the entry, the datalines,
which content corresponds to the search-text,
are shown in the listview (through private void SearchList_OnTextChanged(object sender, TextChangedEventArgs e)).
The user picks a data-line ((private void SearchList_OnTextChanged(object sender, TextChangedEventArgs e))),
and this is being shown in the entry.
The problem is as follows:
First time the user picks a data-line, there are no problems. However, when picking a dataline for the second time,
the program freezes, Visual Studio 2019 freezes, and after a while the message below (in the picture) appears.
I searched for the error for a long time, but sadly -> no luck. In VS 2019 I tried to "Empty symbol cache" and chose "Microsoft Symbol Servers"
under Debug->Options->Debugging->Symbols (picture 2 below). It did not help.
Does anybody have an idea, how to fix this?
Friendly regards
nbs
![]()
![]()
Xaml-design:
![]()
.cs - code -file:
`using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace test_multi.FrameWork.CustomControls
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ListViewSearching : ContentView
{
ObservableCollection<KeyValuePair<string, string>> SearchDataList;
private DataManipulator dsg;
private AlertManager alert;
private string SqlFunction;
private string callMethod;
private string callObject;
public ListViewSearching()
{
InitializeComponent();
dsg = new DataManipulator();
}
public ListViewSearching(String sqlFunction = "", string EntrySearchPlaceholder = "", string callingObject="", string callingMethod = "")
{
callMethod = callingMethod;
callObject = callingObject;
InitializeComponent();
dsg = new DataManipulator();
SqlFunction = sqlFunction;
EntrySearch.Placeholder = EntrySearchPlaceholder;
SearchDataList = new ObservableCollection<KeyValuePair<string, string>>();
FillSearchList();
}
public async void FillSearchList()
{
try
{
SearchListValues poa = new SearchListValues();
IDictionary<string, string> dict = new Dictionary<string, string>
{
{ "COMPANY", Globals.Company }
};
var dataObjects = await dsg.GetDataAsync(SqlFunction, poa, dict, false);
int count = 0;
if (!dsg.IsNullOrEmpty(dataObjects))
{
// All sql-functions shall return 2 variables: ID and NAME
foreach (SearchListValues searchVal in dataObjects)
{
count++;
SearchDataList.Add(new KeyValuePair<string, string>(searchVal.ID, " " + searchVal.NAME));
}
}
}
catch (Exception ex)
{
alert = new AlertManager(Globals.ErrorOccured + Environment.NewLine + ex.Message.ToString(), Globals.AlertInfo);
}
}
private void SearchList_OnTextChanged(object sender, TextChangedEventArgs e)
{
ListViewSearch.IsVisible = true;
ListViewSearch.BeginRefresh();
try
{
var dataSource = SearchDataList.Where(i => i.Key.ToLower().Contains(e.NewTextValue.ToLower()));
if (string.IsNullOrWhiteSpace(e.NewTextValue))
ListViewSearch.IsVisible = false;
else if (dataSource.Any(s => string.IsNullOrEmpty(s.Key)))
ListViewSearch.IsVisible = false;
else
ListViewSearch.ItemsSource = dataSource;
}
catch (Exception ex)
{
ListViewSearch.IsVisible = false;
}
ListViewSearch.EndRefresh();
if (EntrySearch.Text.Trim().Equals(""))
Globals._ValueChosen = "";
}
private void ListViewSearch_OnItemTapped(Object sender, ItemTappedEventArgs e)
{
Globals.ChosenValues = (KeyValuePair<string, string>)e.Item;
String listsd = Globals.ChosenValues.Key + " " + Globals.ChosenValues.Value;
EntrySearch.Text = listsd;
ListViewSearch.IsVisible = false;
((ListView)sender).SelectedItem = null;
}
}
}`