How to display data in one form upon double-clicking an item in another form's listview - vb6

I have 2 forms (2 windows). In first window,I have a tree view (the children are the tables in DB.). On click of a any child, a list view (the data present in the table ) will be displayed on the right side of the tree view.
On double clicking on any row in the list view, another form will be opened. The current requirement is to display the data in the list-view in form2 opened on double clicking a single record.
Private Sub LV_DblClick()
Dim a As New Form2
Display_Temp_DATA
a.Show vbModal
End Sub
LV_DblClick() is in the form1 and it opens the form2. Now, Display_Temp_DATA has SQL query, which
fetches the record from the table and should be displayed in a list view in form2.
Private Sub Display_Temp_DATA()
On Error GoTo errHandler
'Dim liItem As ListItem
'Set liItem = a.ListView1.ListItems.Add(, , "Abcd")
Display_List_Two_Data "Select start, stop FROM tblsignal"
Exit Sub
errHandler:
MsgBox Err.Description
End Sub
I am able to open the form2, but I am finding difficult to display the data in the form2 list view. Any ideas on how to resolve this?

you can add module and variable to it and assign the value to that variable access it on the target form.
not sure but you can also use FormName.VariableName for static variable on the form.

Related

Proper Casing in VB6

I am doing a quiz game in VB6. I need the textbox to automatically capialize the first letter but this code
Private Sub Anstxt_Change()
Anstxt.Text = StrConv(Anstxt.Text, vbProperCase)
End Sub
causes the word to invert. So instead of "Trees" it turns into "Seert"
How do I change this?
Pay attention to where the cursor is positioned in the textbox when the event Change occurs: its at the start of the textbox. Add a Debug.Print statement to see what's going on while you type:
Private Sub Anstxt_Change()
Debug.Print StrConv(Anstxt.Text, vbProperCase)
Anstxt.Text = StrConv(Anstxt.Text, vbProperCase)
End Sub
The output looks like
T
T
Rt
Rt
Ert
Ert
Eert
Eert
Seert
Seert
Two things to notice here: the Change event is triggered twice: once from typing and once from changing the value of the textbox within the Change event. That gives you an idea that manipulating the text of a textbox in its Change event isn't a good idea. I suggest to put this code in the LostFocus event instead.
The second thing to notice is that as the cursor is always at the start of the textbox, the letters you type are inserted there in front of the existing letters. So after you change the .Text property of the textbox, you should position the cursor at the end of the textbox with the .SelStart method:
Anstxt.SelStart = Len(Anstxt.Text)
e.g.
Private Sub Anstxt_Change()
Anstxt.Text = StrConv(Anstxt.Text, vbProperCase)
Anstxt.SelStart = Len(Anstxt.Text)
End Sub

Delete Record VB2010 w/ TableAdapter

This shouldn't be this hard... But it's late.
I am working on a simple form, and trying to delete a record from a connected DataSource while using a TableAdapter. Here is the SQL for the TableAdapter;
DELETE FROM Main WHERE (ID = ?) AND (tbl_Job_Name = ?)
Main is the table name, only two fields.
I am populating a ComboBox with this data, and I am using a Button to call the Delete() action like this;
Private Sub btnDeleteJob_Click(sender As Object, e As System.EventArgs) Handles btnDeleteJob.Click
Dim deleteJobAdapter As New DCGDataSetTableAdapters.MainTableAdapter
deleteJobAdapter.DeleteQuery(ComboBox2.SelectedIndex, ComboBox2.SelectedText)
End Sub
When I break the code I can see the ID value, but the SelectedText field is blank, and of course when it runs through the record is not deleted. I would ideally like to just pass the ID of the selected record in the ComboBox to delete the record. What am I missing?
Try,
deleteJobAdapter.DeleteQuery(ComboBox2.SelectedIndex, ComboBox2.Text)
SelectedText property:
Gets or sets the text that is selected in the editable portion of a ComboBox.
Text property:
Gets or sets the text associated with this control.
You can use the SelectedText property to retrieve or change the currently selected text in a ComboBox control. However, you should be aware that the selection can change automatically because of user interaction. For example, if you retrieve the SelectedText value in a button Click event handler, the value will be an empty string. This is because the selection is automatically cleared when the input focus moves from the combo box to the button.
When the combo box loses focus, the selection point moves to the beginning of the text and any selected text becomes unselected. In this case, getting the SelectedText property retrieves an empty string, and setting the SelectedText property adds the specified value to the beginning of the text.
When I enter the code;
deleteJobAdapter.DeleteQuery(ComboBox2.SelectedIndex, ComboBox2.Text)
My break point shows the correct text from the record, but I did notice that the ID value is incorrect, the SelectedIndex returns a sequential number of the record itself, starting with "0". So it looks like SelectedIndex does not return the actual ID value...
And back to the original issue, the record selected is still not deleted.
This is what I ended up using;
Dim delJobID = ComboBox2.SelectedValue
Dim delJobRowAdpt As New DCGDataSetTableAdapters.MainTableAdapter
Dim delJobRow As DCGDataSet.MainRow
Dim intDelete As Integer
delJobRow = DCGDataSet.Main.FindByID(delJobID)
delJobRow.Delete()

get cursor position another form in windows application

I have two form in my application i am calling two form together from master page.i wrote code in my master page
in top i declared like this
Dim form As New FrmDelivary
Dim frm1 As New FrmrecievedDelivaryRequest
in toolstrip menu event like this:
Dim frm1 As New FrmrecievedDelivaryRequest
frm1.Location = New Point(625, 225)
frm1.MdiParent = Me
frm1.Show()
Dim frm2 As New FrmDelivary
frm2.Location = New Point(965, 0)
frm2.MdiParent = Me
frm.show()
if i press R i want to go my cursor the particular textbox of FrmrecievedDelivaryRequest
if i press D i want to go my cursor the particular textbox of FrmDelivary
How can I do this? i trey something like this in frmMaster_KeyDown event: but same page is showing again. I have already open instance of FrmDelivary, so I don't want to show same page again. I want to just get cursor position to particular textbox of this form
If e.KeyCode = Keys.A Then
form.Show()
form.txtTicket.Focus()
Cursor.Position = form.txtTicket.Location
end if
I am working on vb.net windows application
After
frm1.Show()
place
frm1.txtTicket.Focus()
I don't think you need the Cursor.Position call
Set your frm1 and frm2 variables at the top of the code window so they are accessible from all of the Subs. In your KeyDown event, put
If e.KeyCode = Keys.A Then
frm1.Show()
frm1.txtTicket.Focus()
Cursor.Position = frm1.txtTicket.Location
end if
The problem is that you are instantiating a new copy of the form with the "AS NEW frmDelivery" statement.

Scroll Bar Issues Automatically Scrolling Down To The Last Control

Alright, I designed a form to fit onto the current screen size I use, with the form having a vertical scroll bar to view items further down on the form.
At the bottom of the form, I have a couple of checkboxes a user has to select before clicking the submit button.
Once the user hits the submit buttom, the user can't scroll back up to the beginning of the form. The user can scroll back up, but when they stop scroll, it scrolls to the bottom where the last checkbox was checked off.
I assume by checking this last checkbox is that's setting the focus of that control?
Any suggestions on how to fix the scrolling issue?
Keep a note of the last scroll position, and reapply it on Form_Activate
Try this:
'' Declare at form level
Private LastAutoScrollPos As System.Drawing.Point
Private Sub Form1_Activated(sender As Object, e As System.EventArgs) Handles Me.Activated
Me.AutoScrollPosition = LastAutoScrollPos
End Sub
Private Sub Form1_Scroll(sender As Object, e As System.Windows.Forms.ScrollEventArgs) Handles Me.Scroll
If e.ScrollOrientation = ScrollOrientation.VerticalScroll Then
LastAutoScrollPos = New Point(LastAutoScrollPos.X, e.NewValue)
ElseIf e.ScrollOrientation = ScrollOrientation.HorizontalScroll Then
LastAutoScrollPos = New Point(e.NewValue, LastAutoScrollPos.Y)
End If
End Sub

List view Double click Event

Using VB6
Listview
ID Name
001 Raja
002 Ramu
003 Sajee
..
…
Code
Private Sub listview1_DblClick()
If Not (listview1.SelectedItem Is Nothing) Then
Textbox1.text = listview1.selectedItem(0)
Textbox2.text = listview1.SelectedItem(1)
End If
End Sub
Above code is not showing the values in the text box
How to show the list view row values in the text box.
Need VB6 Code Help
The ListView SelectedItem property does not return a collection of items selected on your ListView, so therefore you can't explicitly get the first selected item, the second selected item, etc. You will need to loop through all ListItems in your ListView and check if each is selected. If it is, do what you want to do.
One problem I see with your sample code is you're using the ListView DblClick event. I might be wrong, but it looks like whenever it fires only one ListView item can be selected (the one that fired the event). A solution for this is to put your code into a new procedure. Here's one that should work:
Private Sub GetSelectedItems()
' Make sure exactly two items are selected on our ListView.
If (CheckListViewSelectedItemCount(listview1, 2)) Then
Dim blnFoundFirstItem As Boolean
blnFoundFirstItem = False
Dim i As Integer
' Find out which items are selected.
For i = 1 To listview1.ListItems.Count
If (listview1.ListItems(i).Selected) Then
' Assign the Text of the 'first' selected item to Textbox1.Text.
If (Not blnFoundFirstItem) Then
Textbox1.Text = listview1.ListItems(i).Text
blnFoundFirstItem = True
' Assign the Text of the 'second' selected item to Textbox2.Text.
Else
Textbox2.Text = listview1.ListItems(i).Text
End If
End If
Next i
Else
MsgBox "You need to select two items."
End If
End Sub
I'm not sure in which order ListItems are iterated through in my For loop. It's possible that what would be assigned to Textbox1.Text in my code you might want to assign to Textbox2.Text.
Your code required at that at least two items are selected on the ListView. I don't know if VB6 has a way to return the number of selected items so I wrote a small function that does this:
' Return True if the passed ListView control has a number of selected items that's equal to the intExpectedItemCount parameter.
Private Function CheckListViewSelectedItemCount(listView As listView, intExpectedItemCount As Integer) As Boolean
Dim intSelectedItemCount As Integer
intSelectedItemCount = 0
Dim i As Integer
For i = 1 To listView.ListItems.Count
If (listView.ListItems(i).Selected) Then
intSelectedItemCount = intSelectedItemCount + 1
End If
Next i
CheckListViewSelectedItemCount = (intSelectedItemCount = intExpectedItemCount)
End Function
I dont have vb6 at hand and its been a while since I used it, but if memory serves me right:
ListView1.SelectedItem will return you a ListViewItem which gives you a Text property along with SubItems property that gives you access to associated columns as an array.

Resources