I had a few forms which has listview controls. In the listview, the contents shown inside all came from an access file.
I wanted to ask about the coding part. Can I use the same coding below for all my list forms, of course some parts need to be changed)? But will that results in any corruption?
I tried to implement the same code on my another form but it fails to show the contents...
And so will this code I made be sufficient? Thanks in advance for any help given...
This is the code I used for my 1st listview control but it cannot seem to be working for my other controls...Code:Private Sub LoadProjects() 'Declare variables Dim objListViewItem As ListViewItem 'Initialize a new instance of the data access base class Using objData As New WDABase Try 'Get all projects in a DataReader object objData.SQL = "usp_SelectProjects" objData.InitializeCommand() objData.OpenConnection() objData.DataReader = objData.Command.ExecuteReader 'See if any data exists before continuing If objData.DataReader.HasRows Then 'Clear previous list lvwProjects.Items.Clear() 'Process all rows While objData.DataReader.Read() 'Create a new ListViewItem objListViewItem = New ListViewItem 'Add the data to the ListViewItem objListViewItem.Text = _ objData.DataReader.Item("PartName") objListViewItem.Tag = objData.DataReader.Item("PartID") 'Add the sub items to the listview item objListViewItem.SubItems.Add( _ objData.DataReader.Item("PartDescription")) objListViewItem.SubItems.Add( _ objData.DataReader.Item("SequenceNumber")) objListViewItem.SubItems.Add( _ Format(objData.DataReader.Item("LastUpdateDate"), "g")) 'Add the ListViewItem to the ListView control lvwProjects.Items.Add(objListViewItem) End While End If objData.DataReader.Close() Catch ExceptionErr As Exception MessageBox.Show(ExceptionErr.Message, strAppTitle) End Try End Using 'Cleanup objListViewItem = Nothing End Sub Private Sub lvwProjects_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles lvwProjects.Click 'Initialize a new instance of the data access base class Using objData As New WDABase Try 'Get the specific project selected in the ListView control objData.SQL = "usp_SelectProject" objData.InitializeCommand() objData.AddParameter("@PartID", Data.OleDb.OleDbType.Guid, 16, _ lvwProjects.SelectedItems.Item(0).Tag) objData.OpenConnection() objData.DataReader = objData.Command.ExecuteReader 'See if any data exists before continuing If objData.DataReader.HasRows Then 'Read the first and only row of data objData.DataReader.Read() 'Populate the Project Details section txtProjectID.Text = _ objData.DataReader.Item("PartID").ToString.ToUpper txtProjectName.Text = _ objData.DataReader.Item("PartName") txtProjectDescription.Text = _ objData.DataReader.Item("PartDescription") txtSequenceNumber.Text = _ objData.DataReader.Item("SequenceNumber") txtProjectUpdateDate.Text = _ Format(objData.DataReader.Item("LastUpdateDate"), "g") End If objData.DataReader.Close() Catch ExceptionErr As Exception MessageBox.Show(ExceptionErr.Message, strAppTitle) End Try End Using End Sub




Reply With Quote