473,396 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Search & Select mechanisms in C#

I am using Xamarin in C#, to build a cross platform BLE app. It is based on this example app using the Monkey.Robotics plugin. All the examples use an `ObservableCollection<IDevice> devices;` line, to populate a ListView with all the scanned results which the user can then manually select, setting a variable to equal that value. i.e. `var device = e.SelectedItem as IDevice;` I am connecting to a known type of device, so after that device is selected, I want to then automatically set the Service and Characteristic variables. The structure of `IDevices` seems a bit tricky, so I thought it would be easiest to enumerate the Services and then automatically select the one that matches the ID I am looking for. Like This:

Expand|Select|Wrap|Line Numbers
  1.     IAdapter adapter;
  2.     IDevice device;
  3.     IService AppService;
  4.  
  5.     ObservableCollection<IService> services;
  6.  
  7.         adapter.DeviceConnected += (s, e) => {
  8.  
  9.             device = e.Device;
  10.             // when services are discovered
  11.             device.ServicesDiscovered += (object se, EventArgs ea) => {
  12.                 if (services.Count == 0)
  13.                     Device.BeginInvokeOnMainThread (() => {
  14.                         foreach (var service in device.Services) {
  15.                             if (service.ID == 0x2A37.UuidFromPartial ()) {
  16.                                 AppService = service as IService;
  17.                             }  else {
  18.                                 services.Add (service);
  19.                             }
  20.                         }
  21.                     } );
  22.             } ;
  23.  
  24.             // start looking for services
  25.             device.DiscoverServices ();
  26.         };
  27.  
  28.  
Is this how you would do it, or would you collect all the results and then check through them? In which case, how would you structure that?

I could also have a function, to `SearchFor(x)`, and set up a ubiquitous `ObservableCollection`, and just throw x into it? Not sure if it could deal with both `IService` and `ICharacteristic`, unless I just has 2 if statements and defined different behaviour for each. Still, it would be god to see some suggestions for the best way to move forward.

Any thoughts / suggestions would be much appreciated. Thanks.
Sep 19 '15 #1
0 1194

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tomomichi Amano | last post by:
Could some one tell me how I can seach and replace only one word in a textBox (THE FIRST WORD THAT COMES AFTER THE CURSOR). I already know how to replace ALL , but I don't know how to REPLACE one,...
0
by: John E. | last post by:
If I select cell at row 0 column 0 in the datagrid, then click on the column header to sort a column (any column), I want to find the row index of where Cell went to, so I can keep it selected. ...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
1
by: Ike | last post by:
I'm absolutely stuck, hoping someone can illuminate my sitatuation. I have a string (a query) where I need to dynamically be able to change one part of the the string (the part where .username...
2
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
6
by: simon.robin.jackson | last post by:
Ok. I need to develop a macro/vba code to do the following. There are at least 300 corrections and its expected for this to happen a lot more in the future. Therefore id like a nice...
5
by: simon.robin.jackson | last post by:
This requires a table called tblReplace with two text fields, old and new. Code: On Error Resume Next Dim db As DAO.Database Dim td As DAO.TableDef Dim f As DAO.Field Set db = CurrentDb
20
by: kashifshahzad | last post by:
See the attached ms access file. I have one combobox I want to search and select a keyword in it. usually combobox give u facility of one keyword which start with. for example I want to see the word...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.