Click here to Skip to main content
15,888,454 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to enable the USB COM Port..? Pin
Jochen Arndt3-Sep-17 23:39
professionalJochen Arndt3-Sep-17 23:39 
AnswerRe: how to enable the USB COM Port..? Pin
Jochen Arndt3-Sep-17 23:49
professionalJochen Arndt3-Sep-17 23:49 
Questionbinding datagridview with entity framework Pin
Member 132649363-Sep-17 7:17
Member 132649363-Sep-17 7:17 
AnswerRe: binding datagridview with entity framework Pin
Mycroft Holmes3-Sep-17 22:49
professionalMycroft Holmes3-Sep-17 22:49 
QuestionUpdate listbox items when button is clicked Pin
Mario Lukačić3-Sep-17 2:19
Mario Lukačić3-Sep-17 2:19 
AnswerRe: Update listbox items when button is clicked Pin
Richard MacCutchan3-Sep-17 21:14
mveRichard MacCutchan3-Sep-17 21:14 
GeneralRe: Update listbox items when button is clicked Pin
Mario Lukačić4-Sep-17 2:31
Mario Lukačić4-Sep-17 2:31 
GeneralRe: Update listbox items when button is clicked Pin
Jochen Arndt4-Sep-17 3:49
professionalJochen Arndt4-Sep-17 3:49 
A listbox may have no item selected. You can check that with ListBox.SelectedIndex which returns -1 if no item is selected.

In your last code snippet you are removing the selected item and adding a new one. As a result, there will be no item selected (removing the selected item will remove also the selection).

Note also that using ListBox.Items.RemoveAt passing the index is better (faster) than searching for an item by the string:
int index = listBox1.SelectedIndex;
if (index >= 0)
    listBox1.Items.RemoveAt(index);

GeneralRe: Update listbox items when button is clicked Pin
Mario Lukačić4-Sep-17 4:01
Mario Lukačić4-Sep-17 4:01 
GeneralRe: Update listbox items when button is clicked Pin
Jochen Arndt4-Sep-17 4:39
professionalJochen Arndt4-Sep-17 4:39 
GeneralRe: Update listbox items when button is clicked Pin
Mario Lukačić4-Sep-17 5:50
Mario Lukačić4-Sep-17 5:50 
GeneralGetting file path and setting to a public variable ?!?! Pin
Mario Lukačić1-Sep-17 8:42
Mario Lukačić1-Sep-17 8:42 
GeneralRe: Getting file path and setting to a public variable ?!?! Pin
Richard Deeming1-Sep-17 9:30
mveRichard Deeming1-Sep-17 9:30 
GeneralRe: Getting file path and setting to a public variable ?!?! Pin
Mario Lukačić1-Sep-17 9:33
Mario Lukačić1-Sep-17 9:33 
QuestionAPI to https://images.google.com Pin
JanningJuul31-Aug-17 21:34
JanningJuul31-Aug-17 21:34 
AnswerRe: API to https://images.google.com Pin
Richard MacCutchan31-Aug-17 22:06
mveRichard MacCutchan31-Aug-17 22:06 
QuestionIP Address Control in for WPF? Pin
Member 1319657431-Aug-17 20:58
Member 1319657431-Aug-17 20:58 
AnswerRe: IP Address Control in for WPF? Pin
Richard MacCutchan31-Aug-17 21:10
mveRichard MacCutchan31-Aug-17 21:10 
GeneralRe: IP Address Control in for WPF? Pin
Member 1319657431-Aug-17 21:17
Member 1319657431-Aug-17 21:17 
GeneralRe: IP Address Control in for WPF? Pin
Richard MacCutchan31-Aug-17 21:35
mveRichard MacCutchan31-Aug-17 21:35 
AnswerRe: IP Address Control in for WPF? Pin
Bernhard Hiller31-Aug-17 22:24
Bernhard Hiller31-Aug-17 22:24 
SuggestionRe: IP Address Control in for WPF? Pin
Richard Deeming1-Sep-17 2:43
mveRichard Deeming1-Sep-17 2:43 
AnswerRe: IP Address Control in for WPF? Pin
Dave Kreskowiak1-Sep-17 7:52
mveDave Kreskowiak1-Sep-17 7:52 
QuestionWhy It displays error? Pin
sulomila31-Aug-17 20:48
sulomila31-Aug-17 20:48 
AnswerRe: Why It displays error? Pin
Richard MacCutchan31-Aug-17 21:09
mveRichard MacCutchan31-Aug-17 21:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.