I am trying to use the panel and buttons to load 2 different forms along with entity framework and ado model stuff. I am trying to load the 2nd form this picture, using the codes running on the first form since they have the same table. but what happen is whenever I close the 2nd form and try to switch on the second user from this form(driverlist), I am still getting the results that I created before on the first user, I kinda think that the 2nd form is not being loaded although I put some code:
Private Sub DriverLicense_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim user_id As Integer = Driverlist.tbxUser_id.Text
Driverlist.db = New [Emme_Subic_Transport_Corporation_Payroll].EmmeSubicEntities
Driverlist.db.UserDetails.Where(Function(c) c.isDeleted <> 1 And c.Id = user_id).Load()
UserDetailBindingSource.DataSource = Driverlist.db.UserDetails.Local
If Driverlist.tbxUser_id.Text.Count < 1 Then
MessageBox.Show("Please Select an Employee ID First", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
Drivertest.Panelswitch(Driverlist)
Else
Me.Show()
End If
End Sub
Private Sub DriverLicense_Activated(sender As Object, e As EventArgs) Handles Me.Activated
Dim user_id As Integer = Driverlist.tbxUser_id.Text
Driverlist.db = New [Emme_Subic_Transport_Corporation_Payroll].EmmeSubicEntities
Driverlist.db.UserDetails.Where(Function(c) c.isDeleted <> 1 And c.Id = user_id).Load()
UserDetailBindingSource.DataSource = Driverlist.db.UserDetails.Local
End Sub
I binded the 2nd form through other resources of data binding from the properties but still on the same resources as the first form. Im pretty new to this so please stop putting negatives on my questions. If you think I am bad at this, I know and I am sorry. by the way this is the code from the buttons and panel if that helps. Thanks everyone.
Sub Panelswitch(Panel As Form)
PanelControl.Controls.Clear()
Panel.TopLevel = False
PanelControl.Controls.Add(Panel)
Panel.Show()
End Sub
Private Sub Btntest_Click(sender As Object, e As EventArgs) Handles Btntest.Click
Panelswitch(Driverlist)
End Sub
Private Sub Btntest2_Click(sender As Object, e As EventArgs) Handles btntest2.Click
Panelswitch(DriverLicense)
End Sub
There are number of things I would avoid, just looking at your pictures, but that goes beyond your question.
Secondly, agreed with the comment, you should revise your question further (I see you tried, but still, it's neither complete or clear).
If I understand correctly, you have container PanelControl, which you fill either with a form DriverList or DriverLicence. I just want to make sure - are you sure you have your instances corectly set? Because I would expect that the switch would act only for displaying correct form, but should behave differently for the [persistent] list DriverList and DriverLicence, which should be probably a new instance every time you want to add a licence. But this code is not shown, just guessing the problem might be along those lines. There are quite few design possibilities, I guess.
Simplified, the point is:
Private Sub Btntest2_Click(sender As Object, e As EventArgs) Handles btntest2.Click
Dim DriverLicenceInstance as new DriverLicence
Panelswitch(DriverLicenseInstance)
End Sub
I also think, that you might have your binding set incorrectly for the 2nd form, the DriverLicence. I'm not proficient in .NET binding, but it seems to me that you declare the bindings as two separate things (comes from the copying the code?). But what you probably need to do is to use the same binding source for both parts. See here: A-Detailed-Data-Binding-Tutorial.
Related
I would like to make a small application what can make easier my work.
I have to make one ordering process some labels where I have a plan and from the plan I have to one excel list making with the labelnames what will be printed by the Manufacturer. We have a lot of type of the label (names) but they are fixing. (160 pieces differentnames).
So I make this always if I get a new plan then I make new label-list. I do it alway by hand cell by cell.. Sometime I have to filling out 400 cell for one plan... I don’t have a lot’s of time to this..
So I started making my first Windows app with Visual Studio(in Windows From – Visual Basic).
I found some cool video, so I already have the „basics”.
I connected one MS Access database to my Project where I would like to store the datas.
And now i have trouble.. I have some Comboboxes. I would like to choose some cases and then I would like to update the database where the rows will be filled with the correct values. If its done, i can this exporting to excel and sendig forward to the Manufacturer.
I have a textbox where I write the Plan name (it linked to the database first Column)
And then:
So the Combobox1 have Sektor A, B, C, D ,E, F (six value)
The Combobox2 have 09RRU, 09RSU, 18RRU ... empty - (eight value)
The Combobox3 have 21RRU, 21RSU, 26RRU ... empty - (eight value)
The Combobox4 have ja or nein (only two value)
and so on.. I have 8 Combobox.
My Idea:
If I select the Sektor A and 09RRU , the another two is empty and nein, then I click on the Update button I would like to get back in database 09.SekA1, 09.SekA2, AISG.SekA
If I select the Sektor A and 09RRU and 21RRU and ja, then after click Update, I would like get 09.SekA1, 09.SekA2, 21.SekA1, 21.SekA2, 09.21.SekA1, 09.21SekA2, AISG.09.21.SekA
….
I can every type of labels line by line writing if needed, I think I have to do this. I don’t think so can I dynamic Arrays making which can the different String e.g. ( Text (09) & Text (.SekA) & Text(1)) creating. I just now started the VB..
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox8.SelectedIndexChanged
SektorForm1()
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
End Sub
Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
End Sub
Private Sub SektorForm1()
BEschriftungenDataSet.Standort.RRU18Column = "18.SekA1"
BEschriftungenDataSet.Standort.RRU21Column = "18.SekA2"
BEschriftungenDataSet.Standort.RRU26Column = "AISG.18.SekA"
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.StandortTableAdapter.Fill(Me.BEschriftungenDataSet.Standort)
ComboBox1.SelectedIndex = 5
ComboBox2.SelectedIndex = 3
ComboBox3.SelectedIndex = 3
ComboBox4.SelectedIndex = 1
ComboBox5.SelectedIndex = 1
ComboBox6.SelectedIndex = 1
ComboBox7.SelectedIndex = 1
ComboBox8.SelectedIndex = 0
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
On Error GoTo SaveErr
StandortBindingSource.EndEdit()
StandortTableAdapter.Update(BEschriftungenDataSet.Standort)
MessageBox.Show("Saved")
End Sub
Could some one for me Helping what is wrong in my code? I tried some data inserting to tha database when I choose someting in Combobox1 but it doesn't work..
I get failures: BC30526 Property'RRU18Column' is 'ReadOnly' and BC30311 Value 'String' cannot be converted to 'DataColumn'..
And giving some help how I sould staring building up my cases to my Combobox chooses..
Thanks guys
I have a project where I am connecting my database to the windows application in vb.net. I am required to make tabs that sort the data in a specific way. For example, it is a student database with names, etc. So When I press the "Student by Last name" tab, it sorts the data by last name in ascending order. So, I made a query which brought a button, but I don't know how to execute the button automatically when the tab page is clicked. The user can't have the control of sorting. The tab does it itself. Any help will be great! I have been looking everywhere for help.
Private Sub TabPage2_Click(sender As Object, e As EventArgs) Handles tbLastName.Click
TabPage1.Hide() "this is made to get rid of previous page, but may be unnecessary"
tbLastName.Show() "this is supposed to show the data"
Sort_By_LastNameToolStripButton.Enabled() "My attempt to execute code from the query button that I made hidden"
End Sub
Try the tab control Selected event to run your database code
Keep a copy of the queried data, and then order it depending on which tab is selected. Use the TabControl.SelectedIndexChanged event
Private queryData As IEnumerable(Of Student)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
queryData = QueryStudentsFromDatabase()
End Sub
Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TabControl1.SelectedIndexChanged
Select Case TabControl1.SelectedIndex
Case 0 ' Last Name
Dim displayData = queryData.OrderBy(Function(s) s.LastName)
Case 1 ' Student ID
Dim displayData = queryData.OrderBy(Function(s) s.ID)
End Select
ListView1.DataSource = displayData ' or whatever
End Sub
This is a very simple example. In the interest of brevity, it is performing work on the UI thread. You can handle offloading the work if you wish.
I am stating VB and since it is so close to VBScript I have been having fun with it. But now I have come across the "Checkboxlist".
My boss saw me making a Windows Forms Application and asked me to make him a interface (GUI) for one of his batch files. In the batch you start by choosing between lines 1 through 10 and it does the rest. So I made a Checkboxlist and made check-boxes going from 1 to 10. Now I am not sure how to tell it that when I click a button a if statement looks at what has been checked and take to appropriate action.
I think i am suppose to start with something like
If CheckedListBox1.Items() = True then
But i know this does not work.
Anything thing will help.
Thank you.
It sounds like you're looking for the ItemCheck event. This event is fired when the checked state of an item changes.
Private Sub HandleCheckedListBox1ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
Dim item As Object = Me.CheckedListBox1.Items.Item(e.Index)
Dim text As String = Me.CheckedListBox1.GetItemText(item)
Select Case e.CurrentValue
Case CheckState.Unchecked
'...
Case CheckState.Checked
'...
Case CheckState.Indeterminate
'...
End Select
End Sub
Or iterate all checked items:
Private Sub HandleButton1Click(sender As Object, e As EventArgs) Handles Button1.Click
For Each item As Object In Me.CheckedListBox1.CheckedItems
Dim text As String = Me.CheckedListBox1.GetItemText(item)
'...
Next
End Sub
First it is worth it to note that I am very new to Visual Basic. I have created a win forms project in Visual Studio 2012 in the Visual Basic Language.
Given the below code, I want to use a combobox named cmbChoose to select from 4 options. These options will be listed in the combobox as:
"Problem 1"
"Problem 2"
"Problem 3"
"Problem 4"
When a user changes the index of cmbChoose, I would like the class object associated with that index to be set to a parent class object to get polymorphic behavior. A flow of this might be:
User selects "Problem 1".
Parent object problem is set to the class object stored at the index of "Problem 1". This object will be problem1 which is created at the top of the class.
User performs actions, problem1 is the current subclass executing functions
User selects "Problem 3".
Parent object problem is set to the class object stored at the index of "Problem 1". This object will be problem3 which is created at the top of the class.
It seems very simple, and I've read on several posts on stackOverflow to try to get the syntax correct, but I'm doing something wrong. I've made sure the combobox can "Use data bound items", and I've tried to set the DataSource, DisplayMember, and ValueMember in different ways. I've tried to access the object stored at a index in different ways.
I do not want to use conditionals to choose the object, it must be the object at the index chosen.
Here is the code. Assume the Problem classes and subclasses are correctly coded (they are). The functions that will need to be changed/implemented correctly are:
Frm_Base_Load() *or another appropriate function to load the combobox
cmbChoose_SelectedIndexChanged()
Public Class Frm_Base
Private problem As Problem
Private problem1 As Problem1 = New Problem1()
Private problem2 As Problem2 = New Problem2()
Private problem3 As Problem3 = New Problem2()
Private problem4 As Problem4 = New Problem2()
Private Sub btnQuit_Click(sender As Object, e As EventArgs) Handles btnQuit.Click
End
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
lstTable.Items.Clear()
End Sub
Private Sub btnDoWhile_Click(sender As Object, e As EventArgs) Handles btnDoWhile.Click
problem.DoWhile()
End Sub
Public Sub btnDoUntil_Click(sender As Object, e As EventArgs) Handles btnDoUntil.Click
problem.DoUntil()
End Sub
Public Sub btnForNext_Click(sender As Object, e As EventArgs) Handles btnForNext.Click
problem.Fornext()
End Sub
Private Sub Frm_Base_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Need to implement
'cmbChoose.DataSource = problem1
'cmbChoose.DisplayMember = "Problem 1"
'cmbChoose.ValueMember = 0
End Sub
Private Sub cmbChoose_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbChoose.SelectedIndexChanged
'Need to change to set parent object 'problem' to sub object at current index
problem = cmbChoose.DataSource
End Sub
End Class
Alright, asuming your Classes are correct this is what you have to do:
In Form_Load:
First create list of Problem
Dim ProbList As New List(Of Problem)
Then add all problems to that List.
ProbList.Add(ProblemX)
Then create a binding source and add the list as datasource
Dim BSProblems As New BindingSource
BSProblems.DataSource = ProbList
Then add the Bindingsource to the combobox.
ComboBox.DataSource = BSProblems
Then add whatever display member you want (I have selected Name, you probably have something different).
ComboBox.DisplayMember = "Name"
Then, in your Problem class you would have to have a property called Name. You create a property like this:
Property Name As String
Notice how it does not say "Public Name..." since that doesn't work (this is a common mistake here).
Finally you have to fetch the Problem base class from SelectedIndexChanged:
problem = CType(ComboBox.SelectedItem, Problem)
Hope this helps you out. Note that the only reason I help you this much is because I had a hard time understanding this myself. Don't expect this kind of help in the future since it does not look like you have tried that many things before posting this question.
VB2010. I must be missing something because I couldn't find a solution after searching for an hour. What I want to do is simple. In my app I want to display a modeless form so that it is floating while the user can still interact with the main form.
dim f as New frmColors
f.Show(Me)
But I only want one instance of the form at any time. So how can I prevent more than once instance being displayed, and if there is one instance then just give it focus?
Does something like this work for you, if the form is already visible you can not do a Show, you can just do a BringToFront, also you can check to see if the Form has been disposed so you can New up another one.
Public Class Form1
Dim f As New frmColors
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If f.IsDisposed Then f = New frmColors 'To handle user closing form
CheckForm(f)
End Sub
Private Sub CheckForm(frm As Form)
If frm.Visible Then
frm.BringToFront()
Else
frm.Show(Me)
End If
End Sub
End Class
Make your form follow the singleton pattern. I can't vouch for this sample, but from the text it appears to do what you want.