How To Load Data From Form1 Datagridview To Another Form & Update
Jan 30, 2011
All I want is to update the selected row data in form1 to another form2
Form1 Objects
Form1 = MainAppForm
DataGridView = DGVMain <= binded
Button = btnUpdate
Form2 Objects
Form2 = frmUpdate
Button = btnSubmit
15 textBoxes = you can see its name in the code below and all of them are data binded
MainAppForm Code
Pass the selectedrow data to form2 (frmUpdate)
Private Sub btnUpdateDouble_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
If DGVMain.SelectedRows.Count = 1 Then
Try
frmUpdate.ItemIDTextBox.Text = DGVMain.CurrentRow.Cells(0).Value.ToString()
frmUpdate.PartTypeTextBox.Text = DGVMain.CurrentRow.Cells(1).Value.ToString()
frmUpdate.PartNameValueTextBox.Text = DGVMain.CurrentRow.Cells(2).Value.ToString()
frmUpdate.PackageTypeTextBox.Text = DGVMain.CurrentRow.Cells(3).Value.ToString()
frmUpdate.QuantityTextBox.Text = DGVMain.CurrentRow.Cells(4).Value.ToString()
frmUpdate.UnitTextBox.Text = DGVMain.CurrentRow.Cells(5).Value.ToString()
frmUpdate.DescriptionTextBox.Text = DGVMain.CurrentRow.Cells(6).Value.ToString()
frmUpdate.LocationTextBox.Text = DGVMain.CurrentRow.Cells(7).Value.ToString()
frmUpdate.ProjectBoardTextBox.Text = DGVMain.CurrentRow.Cells(8).Value.ToString()
frmUpdate.CommentsTextBox.Text = DGVMain.CurrentRow.Cells(9).Value.ToString()
frmUpdate.OrderCodeTextBox.Text = DGVMain.CurrentRow.Cells(10).Value.ToString()
frmUpdate.CurrencyTextBox.Text = DGVMain.CurrentRow.Cells(11).Value.ToString()
frmUpdate.UnitPriceTextBox.Text = DGVMain.CurrentRow.Cells(12).Value.ToString()
frmUpdate.SupplierTextBox.Text = DGVMain.CurrentRow.Cells(13).Value.ToString()
frmUpdate.ManufacturerTextBox.Text = DGVMain.CurrentRow.Cells(14).Value.ToString()
frmUpdate.Show()
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
ElseIf DGVMain.SelectedRows.Count = 0 Then
MsgBox("Please select one item to update!", MsgBoxStyle.Information, "Update")
Else
MsgBox("Updating multiple Items is not allowed!", MsgBoxStyle.Information, "Update")
End If
End Sub
Form2 Code
I want to update the data by this code, but it refresh only the data in Form1
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Me.Validate()
Me.SparePartsBindingSource.EndEdit()
Me.SparePartsTableAdapter.Update(Me.InventoryDBDataSet.SpareParts)
'Refresh
MainAppForm.SparePartsTableAdapter.Fill(MainAppForm.InventoryDBDataSet.SpareParts)
End Sub
No problem in updating the data if I put the code below in Form2 load event
Me.SparePartsTableAdapter.Fill(InventoryDBDataSet.SpareParts)
but the problem is, it will refresh all the data in the Form2, and my code in Form1 becomes useless.
Thanks in advance!
View 1 Replies
ADVERTISEMENT
Oct 7, 2011
I have a form consisting of datagridview and two buttons of update and load all.. I have used fillby method to obtain data from database. The query seems to be working fine, except that the data is not shown in the gridview.As in, for the qeury, if the returned rows are 2, it will show 3 rows in the gridview, but all empty.
Imports System.Data
Imports System.Data.OleDb
Imports System.EventArgs
[code].....
View 2 Replies
Nov 10, 2009
I have a project in which i have a form in which there is add button to add pages. In form load the last entered page populates all the fields. Now thing is if user edits the values in controls it has to update the db with those fields and if the page doesn't exist in db it has to insert.
Here is my code
Private Sub inserting()
Dim cn As New OleDb.OleDbConnection
'Dim selectquery As String
cn.ConnectionString = ""
Dim cmd As New OleDb.OleDbCommand
[Code] .....
I initialized a global variable x and set its value to 0 in page load and in add button click to 1. Depending on x value it either inserts or updates the db in form closing and add button click. Now whats happening is If the user clicks on add button the page increments but if user doen;t enter any values and tries to close the empty form, value of x =1 and it tries to insert but as there are blank fields cmd.executenonquery throws an error.
"The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data."
What should I do so that it doesn't give an error. I am using access db.I even checked in db Except for primary key(pageno) all other fields have "allow zero length" as YES & "required" to NO.
View 8 Replies
Mar 10, 2010
regarding the DataGridView Checkbox.. I have two Forms, The 1st one has a datagridview..but in order to load the data to form1 datagridview, i need to open another form w/c also has a datagridview w/checkboxes on it.. I need to select a data in the form2 datagridview w/the use of checkbox..when i select an item..then press the ok button, the checked checkbox with the info corresponds to the data i selected will appear in the form1 datagridview. I have done this and works fine, but when i select two data or when i checked two items on the form2 datagridview.. only one info is added on the form1 datagridview.. here is my
[Code]...
View 2 Replies
May 1, 2012
I have searched the web and this site for an answer but have not been able to solve this problem.I am not able to place a flashing cursor in a specified cell of a data bound DataGridView on Form_Load.My test project consists of a single Visual Basic 2008 form with a database created in Microsoft SQL Express 2005 using the Add New Data Source in the Data Sources window.The database has one table consisting of 2 columns.Column 1 being the primary key with Identity Specification set to On.The second column is a VarChar50.The DataGridView was placed on the form by dragging it from the Data Sources window thereby creating the Binding Navigator and the Private_Sub Form_Load code.I have added the code that should put the cursor where I want it.[code]
View 2 Replies
Jun 10, 2009
Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'Para abrir un formulario independiente /Open independent form
[Code].....
View 2 Replies
Mar 4, 2009
im working on windows application.In this Application iam using two forms one form is for save and modifying the details of the Patient. This First form contains a 'Find Patient' Button .when we click on button. new form will be open code in the 'Find Patient' button click
'open a form2 from form1
dim f2 as new form2
f2.show
In this form2 iam searching for particular patient according to their Id and retrieveing all the details of the patient in a datagridview wat i have to do is when i click on any cell in datagridview of a particular employee . the details of the particular employee should be shown on the first form1 by hiding this second form2'code in the datagridview_celldoubleclick()
Private Sub grv_Patientdetails_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles grv_Patientdetails.CellDoubleClick
Try
[code].....
data will be retreiveing correctly. but it is opening in a new form but already old form1 is opened beneath the form2 ? new form should not be opened and data should be retrieved in the first form which is already opened how should i do this?
View 1 Replies
Nov 16, 2010
I'm trying to execute different code depending on the button clicked (button 4 or 5) on Form1, but when I click on button5 to activitae the code on the Form2's Load event everything is Ok, but when I click the back button to return to Form 1 and click on the Button4 to activate the code on the Form2's Load event again, it doesn't active the Form's Load event, is there a way to form the form load event every time I access it from Form1? [code]
View 7 Replies
Oct 27, 2009
In my window application, Form1 variable eg. Public str as string. value blank/null when move to Form2 and Back to Form1. How to maintain Form1 varable's value when back to Form1 In vb.net if any one know, reply me soon
View 2 Replies
Aug 2, 2011
i have my database table in textbox i want to add a comment button when they click on that it should open a new form with another textbox from the same table.my problem is i cannot get it to load the selected rows comment colum.
My table is containing for example, username, password, name, surname and comment
on form1 i have username, password, name and surname with a button that should open form2 with comment with multilines.so if i have selected a username for example test and i click on comment i want to add data to the username test.
View 2 Replies
Jun 18, 2010
I Want A Web-Browser (WebBrowser1.Navigate [url]) to navigate to a direct site witha .txt file so the text appears in the browser. ok that works.
When Form1 Loads I want To Use This But It Wont Work WebBrowser1.Navigate[url] but it will only work if form1 contains WebBrowser1.Navigate[url] and button1 = TextBox1.Text = WebBrowser1.Document.Body.InnerText.
Final Question How Can I Get Form1.Load To Do Both Operations
View 4 Replies
Mar 26, 2012
I'm creating part of a program which calculates vacation hours multiplied by accrual rate. As of right now all parts of the form are functioning and saving/retrieving data from a csv text file. My problem is that I'd like to bring the process out of a button.click event and into Form_Load. Currently when I click a listview item (lvwData.SelectedItems) it populates a textbox (txtAvail), then recalculates the textbox value based off my formula (hours) and updates the listview's 4th column item. To update each column daily, I currently have to click each row, then my button, then move onto the next item. I'm looking for a way to grab the 4th column, recalculate it and update the listview without having to select each row.
[Code]...
View 4 Replies
Feb 5, 2012
I have a program, that on form load, updates a value. The problem is, that it doesn't work!
my
Imports MySql.Data.MySqlClient
Public Class Form1
Dim MysqlConn As MySqlConnection
Dim UserCommand As New MySqlCommand
Dim SQL As String
[Code] .....
And the problem is that it doesn't update the points. I set the points to 10 via PHPmyadmin, and run the program, but when i go back to PHPmyadmin, its still 10.
View 2 Replies
Mar 15, 2012
My code is working fine I just need a way to reset the DataAdapter1 into 0 (like reset) So if the user hit the button search 2 times to shows up only 1 time the elements of database "product".. If i used the code below and hit 2 times the button the DataGridView show 10 product for examplat the first time and +10 for the second, a total of 20 products, even if I search then edit a product and search again it's fixed the previous table and prints again 2 times the table....
DataAdapter1.SelectCommand = Sql2 ''database load
DataAdapter1.Fill(ds2, "products") ''dataset
DataGridView1.DataSource = ds2
[code].....
View 13 Replies
Apr 7, 2012
I have a couple of tables in a sql server database and i want to load the data from them in form load.
Here is the code i use to load the first table
connection string here
Con.Open()
Dim objCmd As New SqlCommand("SELECT * FROM Customers", Con)
Dim cust As SqlDataReader = objCmd.ExecuteReader()
[Code]...
View 2 Replies
Mar 15, 2011
i have code to load data from database to DataGridView.
VB.NET
Imports System.DataImports System.Data.OleDb Public Class Form1 Dim dt As New DataTable Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.WindowState = FormWindowState.Maximized End Sub Sub setData()
[Code]...
View 4 Replies
May 10, 2011
I am loading data from query into a dataadapter and then into a dataset.the datadridview datasource is the set to the dataset.but it takes too long to load the data into the datagridview.
View 2 Replies
Mar 12, 2011
I create more then 10 columns in Access 2010 and I have a lot of rows. I write code already to load data to my datagridview, but I want to know to how to load data with progressbar untill finish. *If loading data does not finish the progressbar does not finish,too.
View 8 Replies
Mar 16, 2009
That's all I want to do but I get errors when I do this:
Form2.show ()
Me.close ()
Using VB2008
View 8 Replies
Sep 19, 2009
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.Show()
Me.Close()
End Sub
i have this code on my MDI parent and on button click i would like Parent to close and form2 to load/show.yet with current code when i click button it closes all the app and doesnt load from2
View 3 Replies
Jun 21, 2012
What im trying to do is load form1 and form2 at the same time.I have a setting called hideform2.So when i run both forms at the start up i want to get it so when they click on a close button and form 2 hides.I want it so when they run the application again it dosent show form2 anymore?
View 5 Replies
Mar 13, 2011
I have 2 forms, each one with a datagridview.I want to transfer all the DataGridView Rows from From2 to another DataGridView of Form1. but it's not possible.
[Code]...
View 12 Replies
Apr 30, 2009
i want to update data in database using datagridview actually i am displaying the data in datagridview and after that i want to update some rows data directly modifying the displayed data into the datagridview
how can be done like this
View 1 Replies
Feb 7, 2010
I was wondering if there is any way to load data from excel sheet into a datagridview in VB2008 dynamically. I have looked at few data connection codes but all of them involve the excel sheet and thw workbook name. Is there anyway that I enter the excel sheet name in a inputbox and the data from excel loads into datagridview without hardcoding the sheet name. I know data can be imported using the below code, here the programmer has to mention the excel workbook name, path and sheet name. [code]I am developing a program to perform some calculations and my data is in a number of excel workbooks and worksheets. I need to be able to bring the data from these excel sheets into the datagridview to perform calculations. So I was thinking if I could mention the excel sheet name in the GUI and then accordingly the data from that particular sheet would be loaded into the datagridview to perform calculations.
View 5 Replies
Jul 16, 2009
I have a datagridview which have 5 columns. The name of the columns are T,C,F,S,H.
I have a text file which contain lines like this.
T240C3.175F012S27H2000
T239C0.95F034S55H1000
T236C1.2F029S48H2000
T234C1.6F029S48H2000
So i want to display this data in datagried view. I must display the number beside T to T column, the number beside C to C column and so on. It should only display number in the respective column. It should not display the T,C and so on.
View 10 Replies
Nov 15, 2011
I have the option to save the contents of the listview that was saved into text file.now i would like to load the text file into datagridview in vb.net but i have no idea how to do it as this is my first time in doing it and i had googled around but couldn't find the information i needed.
View 11 Replies
Dec 27, 2009
You have a form with 5 Textboxes and 1 button.
Write the code missing in Form1.Load so when the button is clicked, Textbox5 takes the value Done
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, _
[CODE]...
View 16 Replies
Nov 1, 2010
I have tried to use Form2.show vbModal but "vbModal" underlines with a blue error line. I have a second form I wish to pop up and get some data before Form1 code continues. I will have a button or some other means to close the form then I wish Form2 to take that response and go...
View 9 Replies
Nov 24, 2009
I have 2 forms
1. Form1
2. Form2
It always loads Form1 but never Form2 when i press the play button.How can i make it load Form2 instead of Form1 when i press the play button?
View 1 Replies
May 25, 2009
How can i get form2 to to load exactly center of form1 or a location within the form when i get form2 to show, no matter the location of form1.[code]...
View 10 Replies