Click here to Skip to main content
16,004,901 members
Home / Discussions / C#
   

C#

 
QuestionSetPixel on Controls Pin
Member 1221969226-Dec-15 21:28
Member 1221969226-Dec-15 21:28 
AnswerRe: SetPixel on Controls Pin
Richard MacCutchan26-Dec-15 22:09
mveRichard MacCutchan26-Dec-15 22:09 
AnswerRe: SetPixel on Controls Pin
OriginalGriff26-Dec-15 22:14
mveOriginalGriff26-Dec-15 22:14 
AnswerRe: SetPixel on Controls Pin
Dave Kreskowiak27-Dec-15 11:04
mveDave Kreskowiak27-Dec-15 11:04 
AnswerRe: SetPixel on Controls Pin
BillWoodruff27-Dec-15 22:19
professionalBillWoodruff27-Dec-15 22:19 
AnswerRe: SetPixel on Controls Pin
John Torjo28-Dec-15 0:05
professionalJohn Torjo28-Dec-15 0:05 
QuestionHow can I replace all text in a listBox1 that matches "some text " with "other text "? Pin
Member 1041097226-Dec-15 8:41
Member 1041097226-Dec-15 8:41 
AnswerRe: How can I replace all text in a listBox1 that matches "some text " with "other text "? Pin
BillWoodruff26-Dec-15 9:46
professionalBillWoodruff26-Dec-15 9:46 
I would approach this by:
// defining the ListBox Items in code   
private List<string> listItemData = new List<string>
{
    "one","two","three","two","five","six","seven","two","nine","ten"
};

// setting the DataSource property of the ListBox to use the List<string>
private void Form1_Load(object sender, EventArgs e)
{
    listBox1.DataSource = listItemData;
}

// creating a method to do substitution
private void ReplaceInListBox(string toFind, string toReplace, bool replaceOneItemOnly)
{
    int ndx;
    string itm;

    for (int i = 0; i < listItemData.Count; i++)
    {
        itm = listItemData[i];

        if (itm == toFind)
        {
            ndx = listItemData.IndexOf(itm);
            listItemData.RemoveAt(ndx);
            listItemData.Insert(ndx, toReplace);

            if (replaceOneItemOnly) break;
        }
    }

    // necessary to reset the DataSource
    // in order to refresh it
    listBox1.DataSource = null;
    listBox1.DataSource = listItemData;
    listBox1.Invalidate();
}

// test like this:
private void SomeButton_Click(object sender, EventArgs e)
{
    ReplaceInListBox("two", "twenty", false);
}
By the way, it would be interesting to know why it is you want to dynamically change the ListBox Items; that's something I would avoid unless it was absolutely necessary.
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin

QuestionDynamic Treeview using C# Pin
Member 1124005623-Dec-15 19:49
Member 1124005623-Dec-15 19:49 
SuggestionRe: Dynamic Treeview using C# Pin
CHill6023-Dec-15 23:14
mveCHill6023-Dec-15 23:14 
SuggestionRe: Dynamic Treeview using C# Pin
Richard Deeming4-Jan-16 3:26
mveRichard Deeming4-Jan-16 3:26 
QuestionCountdown timer Pin
Enzotech223-Dec-15 11:05
Enzotech223-Dec-15 11:05 
AnswerRe: Countdown timer Pin
Richard MacCutchan23-Dec-15 11:14
mveRichard MacCutchan23-Dec-15 11:14 
QuestionHow do I read data from USB Virtual COM in C#? Pin
naouf1023-Dec-15 3:27
naouf1023-Dec-15 3:27 
AnswerRe: How do I read data from USB Virtual COM in C#? Pin
OriginalGriff23-Dec-15 3:55
mveOriginalGriff23-Dec-15 3:55 
GeneralRe: How do I read data from USB Virtual COM in C#? Pin
naouf1023-Dec-15 11:41
naouf1023-Dec-15 11:41 
AnswerRe: How do I read data from USB Virtual COM in C#? Pin
Gerry Schmitz23-Dec-15 11:07
mveGerry Schmitz23-Dec-15 11:07 
GeneralRe: How do I read data from USB Virtual COM in C#? Pin
naouf1023-Dec-15 11:39
naouf1023-Dec-15 11:39 
AnswerRe: How do I read data from USB Virtual COM in C#? Pin
OriginalGriff23-Dec-15 11:57
mveOriginalGriff23-Dec-15 11:57 
GeneralRe: How do I read data from USB Virtual COM in C#? Pin
naouf1023-Dec-15 14:30
naouf1023-Dec-15 14:30 
GeneralRe: How do I read data from USB Virtual COM in C#? Pin
Gerry Schmitz23-Dec-15 12:05
mveGerry Schmitz23-Dec-15 12:05 
GeneralRe: How do I read data from USB Virtual COM in C#? Pin
naouf1023-Dec-15 14:45
naouf1023-Dec-15 14:45 
GeneralRe: How do I read data from USB Virtual COM in C#? Pin
Gerry Schmitz23-Dec-15 16:11
mveGerry Schmitz23-Dec-15 16:11 
AnswerRe: How do I read data from USB Virtual COM in C#? Pin
Luc Pattyn23-Dec-15 17:24
sitebuilderLuc Pattyn23-Dec-15 17:24 
GeneralRe: How do I read data from USB Virtual COM in C#? Pin
naouf1026-Dec-15 3:44
naouf1026-Dec-15 3:44 

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.