Дружественное поле со списком имен портов С# Windows Form (проблема с функцией) ⇐ C#
-
Anonymous
Дружественное поле со списком имен портов С# Windows Form (проблема с функцией)
I've been trying to display the friendly port name for a while now.
I found this question-answer (link below) which has helped me a lot and which I'm going to use to do it.
However, I'm having a little trouble with the "GetAlphaNumericOrderToken()" function. Visual Studio tells me that it doesn't contain a definition or that it doesn't have a reference. (Screenshot below) I've tried a lot of things with references, and I've looked into this function, but I can't find anything ...
Note that this is the only part of the code where it gives me an error.
Could you help me? Thanks in advance
A-Q link : friendly port name combobox c# Windows Form
My adapted code :
private void LoadAvailablePorts() { // Get friendly names to go along with the actual portNames using (var searcher = new ManagementObjectSearcher("SELECT * FROM WIN32_SERIALPORT")) { var portDictionary = new Dictionary(); var portNames = SerialPort.GetPortNames().OrderByDescending(s => s.GetAlphaNumericOrderToken()).ToArray(); var portList = searcher.Get().Cast().ToList(); foreach (var portName in portNames) { // WMI does not always find all com ports so provide a null alternative var portDesc = portList.Where(p => p["DeviceID"].ToString() == portName.ToString()).Select(q => q["Caption"].ToString()).FirstOrDefault() ?? portName.ToString(); portDictionary.Add(portName.ToString(), portDesc); } comSelect.DataSource = new BindingSource(portDictionary, null); comSelect.DisplayMember = "Value"; comSelect.ValueMember = "Key"; // I set my comboBox Selected entry to be the one with a friendly name // beginning with "Teensy" (of course yours will be different, // or you can leave this out) comSelect.SelectedIndex = comSelect.FindString("Teensy"); // -1 if not found if (comSelect.SelectedIndex < 0) comSelect.SelectedIndex = 0; } } Screenshot of the error message
Источник: https://stackoverflow.com/questions/780 ... on-problem
I've been trying to display the friendly port name for a while now.
I found this question-answer (link below) which has helped me a lot and which I'm going to use to do it.
However, I'm having a little trouble with the "GetAlphaNumericOrderToken()" function. Visual Studio tells me that it doesn't contain a definition or that it doesn't have a reference. (Screenshot below) I've tried a lot of things with references, and I've looked into this function, but I can't find anything ...
Note that this is the only part of the code where it gives me an error.
Could you help me? Thanks in advance
A-Q link : friendly port name combobox c# Windows Form
My adapted code :
private void LoadAvailablePorts() { // Get friendly names to go along with the actual portNames using (var searcher = new ManagementObjectSearcher("SELECT * FROM WIN32_SERIALPORT")) { var portDictionary = new Dictionary(); var portNames = SerialPort.GetPortNames().OrderByDescending(s => s.GetAlphaNumericOrderToken()).ToArray(); var portList = searcher.Get().Cast().ToList(); foreach (var portName in portNames) { // WMI does not always find all com ports so provide a null alternative var portDesc = portList.Where(p => p["DeviceID"].ToString() == portName.ToString()).Select(q => q["Caption"].ToString()).FirstOrDefault() ?? portName.ToString(); portDictionary.Add(portName.ToString(), portDesc); } comSelect.DataSource = new BindingSource(portDictionary, null); comSelect.DisplayMember = "Value"; comSelect.ValueMember = "Key"; // I set my comboBox Selected entry to be the one with a friendly name // beginning with "Teensy" (of course yours will be different, // or you can leave this out) comSelect.SelectedIndex = comSelect.FindString("Teensy"); // -1 if not found if (comSelect.SelectedIndex < 0) comSelect.SelectedIndex = 0; } } Screenshot of the error message
Источник: https://stackoverflow.com/questions/780 ... on-problem
Мобильная версия