i have a problem with the listview
i have 2 combobox and 2 textbox and one listview call listview3
after i add in the data to the listview how can i hightlight the item that i add in to the listview ????
thanx for the help
:( :( :(
Printable View
i have a problem with the listview
i have 2 combobox and 2 textbox and one listview call listview3
after i add in the data to the listview how can i hightlight the item that i add in to the listview ????
thanx for the help
:( :( :(
hope i don't bark the wrong tree. though monkeys don't bark...VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ListView1.Items.Add(TextBox1.Text).BackColor = Color.Brown 'monkey If ListView1.Items.Count > 1 Then ListView1.Items(ListView1.Items.Count - 2).BackColor = Nothing End If End Sub
Well Brown since you seem to know your ListView pretty well, can you tell me why my SubItems won't Add??
VB Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim LvItem As New ListViewItem Dim int1, int2, ans As Integer For int1 = 1 To 12 For int2 = 1 To 12 ' Works fine! LvItem = lstTable.Items.Add(int1.ToString) ' Doesn't Work LvItem.SubItems.Add = ("X") ' Doesn't Work LvItem.SubItems.Add = (int2.ToString) ' Doesn't Work LvItem.SubItems.Add = ("=") ' Works fine! ans = int1 * int2 ' Doesn't Work LvItem.SubItems.Add = (ans.ToString) Next Next End Sub
There are a couple of problems with your code.
First you are trying to add subitems to an item that was creaetd from a listview with predefined column headers so your subitems already exist.
Second you are trying to assign a string to an object reference that expects a subitem object.
try this:
VB Code:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim LvItem As New ListViewItem Dim int1, int2, ans As Integer For int1 = 1 To 12 LvItem = lstTable.Items.Add(int1.ToString) For int2 = 1 To 12 LvItem.SubItems(1).Text = ("X") LvItem.SubItems(2).Text = (int2.ToString) LvItem.SubItems(3).Text = ("=") ans = int1 * int2 LvItem.SubItems(4).Text = (ans.ToString) Next Next End Sub