Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
740 views
in Technique[技术] by (71.8m points)

c# - How to change color of selected item in ListBox?

I have a ListBox control with some items and I want to change color of selected item... How can I do it in C# (WinForms)? Help me please :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is how you can set, say Red color, to the selected ASP.NET ListBox items:

 <asp:ListBox runat="server" ID="ListBox1">
    <asp:ListItem Text="Text1"></asp:ListItem>
    <asp:ListItem Text="Text2"></asp:ListItem>
</asp:ListBox>


        if(ListBox1.SelectedItem != null)
            ListBox1.SelectedItem.Attributes["style"] = "color:red";

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...