| | |
Add Items to Listview
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 324
Reputation:
Solved Threads: 7
I want to convert VB.Net to C# code
VB.NET-
C#
I m getting Errors
Error 1 The best overloaded method match for 'System.Windows.Forms.ListView.ListViewItemCollection.Add(string)' has some invalid arguments
Error 2 Argument '1': cannot convert from 'method group' to 'string'
VB.NET-
C# Syntax (Toggle Plain Text)
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim lCount As Integer For lCount = 1 To 5 ListView1.Items.Add(lCount.ToString) Next Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim lCount As Integer For lCount = 0 To ListView1.Items.Count MsgBox(ListView1.Items(lCount).Text) Next Catch ex As Exception MsgBox(ex.Message) End Try End Sub End Class
C#
C# Syntax (Toggle Plain Text)
private void Form1_Load(object sender, EventArgs e) { int lcount; for (lcount = 0; lcount <= 5;lcount ++ ) { listView1.Items.Add( lcount.ToString); } }
I m getting Errors
Error 1 The best overloaded method match for 'System.Windows.Forms.ListView.ListViewItemCollection.Add(string)' has some invalid arguments
Error 2 Argument '1': cannot convert from 'method group' to 'string'
•
•
Join Date: Jul 2009
Posts: 940
Reputation:
Solved Threads: 154
Your next loop should look like:
to replace:
NOTE: Not sure how VB handles declaration of iterator inside the loop (
C# Syntax (Toggle Plain Text)
for (int lCount = 0; lCount < ListView1.Items.Count; lCount++) MessageBox.Show(ListView1.Items[lCount].Text)
to replace:
vb Syntax (Toggle Plain Text)
Dim lCount As Integer For lCount = 0 To ListView1.Items.Count MsgBox(ListView1.Items(lCount).Text) Next
NOTE: Not sure how VB handles declaration of iterator inside the loop (
lCount (maybe you can't), but in C# the variable lCount (as I demonstrated it) will no longer be in scope outside the confines of the loop block (single statement in this case). Last edited by DdoubleD; Sep 20th, 2009 at 11:46 am. Reason: added NOTE
![]() |
Similar Threads
- how to add more than field value listview (VB.NET)
- How to dynamically add items to a control's property? (VB.NET)
- Listview and text file (C++)
- Pass items from one listview to another (VB.NET)
- Checboxes in a Listview (VB.NET)
- ListView Items manipulation- row wise looping (VB.NET)
- Problems instering items into a listview (VB.NET)
- add sub menu items to css menu? (JavaScript / DHTML / AJAX)
- Add an item to a listview using API (Visual Basic 4 / 5 / 6)
Other Threads in the C# Forum
- Previous Thread: Stopping an application process
- Next Thread: SQl connectivity Problem
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format formatting forms function gdi+ httpwebrequest image index input install java label list listbox listener mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






