cugone Posted October 9, 2008 Posted October 9, 2008 I have the following code: Select Case localType Case "Relations" i = 0 For j = 0 To Me.listRelations.Count - 1 li.SubItems.Add(New ListViewItem.ListViewSubItem()) li.Text = Me.listRelations.Item(j).Name i += 1 li.SubItems(i).Text = Me.listRelations.Item(j).Relation 'Copy listview item, attempt to store into array. li_copy = TryCast(li.Clone(), ListViewItem) If li_copy Is Nothing Then MessageBox.Show("There was an error inserting record " & _ (ItemCount + 1).ToString & _ " into the list. It contains invalid data or is empty.", _ My.Application.Info.Title, _ MessageBoxButtons.OK, _ MessageBoxIcon.Error) Continue For Else ReDim Preserve aryItems(ItemCount) aryItems(ItemCount) = li_copy End If ItemCount += 1 'Reset values for populating with next record. li.SubItems.Clear() li.Text = "" li_copy = Nothing i = 0 Next j ... It repeats exactly as is multiple times with the exception of "listRelations" changes to one of many other different object names based on the select case at the time. I was wondering, is there a way to put this all in one subroutine and have the object acted on changed based on string parameters passed in? Quote
Nate Bross Posted October 9, 2008 Posted October 9, 2008 You may want to look into this method: this.Controls.Find(string,true); you will then need to pass in the exact name, not just part of it. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Administrators PlausiblyDamp Posted October 10, 2008 Administrators Posted October 10, 2008 If this is a routine of it's own you could just pass the relevant control in as a parameter. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
cugone Posted October 10, 2008 Author Posted October 10, 2008 I was thinking about that, but the "list..." prefixed objects are not controls, they are List (Of T) objects. Quote
Nate Bross Posted October 10, 2008 Posted October 10, 2008 Something like this should work, no? public void doWork<T>(IList<T> theList) { } Public Sub doWork(Of T)(theList As IList(Of T)) End Sub Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.