|
<br />
...<br />
Dim dt as New DataTable<br />
dt.Columns.Add("Name")<br />
dt.Columns.Add("Age")<br />
<br />
With dgv1<br />
For Each dr As DataGridViewRow In .Rows<br />
Dim obj() As Object = {dr.Cells("Name").Value,dr.Cells("Age").Value}<br />
dt.Rows.Add(obj)<br />
Next<br />
End With<br />
<br />
frm2.DGV2.DataSource = dt<br />
<br />
If you are using a DataSet/DataTable to populate your initial DGV then create a DataView of the DataTable and use that as the datasource for your second DGV.
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
|
|
|
|
|
Thanks Andy, I am not getting one thing.
Which part of the code will be in Form1 and which will be in Form2.
I mean, Datagridview1 is in Form1 and Datagridview2 is in Form2, so how to access the Datagridview1 rows from second form form2.
Can You please clarify this?
Thanks
|
|
|
|
|
Code In Form1 - I assume you open Form2 from a Click Event? or similar.
Public Class Form1<br />
<br />
...<br />
<br />
Private Sub Button1_Click(...)...<br />
<br />
Dim dt As New DataTable<br />
dt.Columns.Add("Name")<br />
dt.Columns.Add("Age")<br />
<br />
With DataGridView1<br />
For Each dr As DataGridViewRow In .Rows<br />
Dim obj() As Object = {dr.Cells("Name").Value, dr.Cells("Age").Value} ' EDIT Dim obj() As Object = ...<br />
dt.Rows.Add(obj)<br />
Next<br />
End With<br />
<br />
Dim frm As New Form2<br />
frm.DataGridView2.DataSource = dt<br />
<br />
frm.Show()<br />
<br />
End Sub<br />
<br />
...<br />
<br />
End Class
Does that make it clearer?
[EDIT: Dim obj() as Object = ...]
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
modified on Sunday, September 20, 2009 6:46 AM
|
|
|
|
|
It is throwing Error :
Error: Name 'obj' is not declared.
How to fix this?
|
|
|
|
|
Hi Andy,
I have already created columns in Datagridview2, these are "Name" and "Age".
I have filtered the Datagridview1 and Add those filtered rows in "Name" and "Age" of Datagridview2.
I am trying to understand Your code but not able to copy those filtered rows in Datagridview2.
Kindly help.
|
|
|
|
|
Public Class Form1
Dim dt As New DataTable
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
With dt
.Columns.Add("Name")
.Columns.Add("Age")
.Columns.Add("Salary")
.Columns.Add("Date")
End With
Dim obj() As Object = {"David", 23, 12000, New Date(2009, 9, 20, 0, 0, 0)}
dt.Rows.Add(obj)
Dim obj2() As Object = {"Frank", 33, 22000, New Date(2009, 5, 3, 0, 0, 0)}
dt.Rows.Add(obj2)
DataGridView1.DataSource = dt
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As New Form2
Dim dt As New DataTable
dt.Columns.Add("Name")
dt.Columns.Add("Age")
For Each dr As DataGridViewRow In DataGridView1.Rows
Dim obj() As Object = {dr.Cells("Name").Value, dr.Cells("Age").Value}
dt.Rows.Add(obj)
Next
frm.DataGridView1.DataSource = dt
frm.Show()
End Sub
End Class
This works. I dont know what more you want. Anything else can be worked out from this code.
By the way, you have not shown me anything that YOU have written, yet I have basically written the entire code for you.
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
|
|
|
|
|
My code is like this :
I have one Datagridview1 in Form1, for which I created a Table through Database Explorer in VB 2008.
Table name is "client_details" with Columns, Name, Age, Salary, Date.
I populated them through this following function :
Sub Add_client()
cmd = New SqlCommand("Insert Into client_details(Name,Age, Salary,Date)
Values(@Name,@Age,@Salary,@Date)", con)
cmd.Parameters.AddWithValue("@Name", TextBox15.Text)
cmd.Parameters.AddWithValue("@Age", TextBox2.Text)
cmd.Parameters.AddWithValue("@Salary", TextBox3.Text)
cmd.Parameters.AddWithValue("@Date", TextBox7.Text)
End Sub
Where,
Public con = New SqlConnection("Data Source=.\demo22.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
Public cmd As SqlCommand = Nothing
Public myDA As SqlDataAdapter = Nothing
Public myDataSet As DataSet
-->Now in Form1, I am loading the DataGridView1 with all the entries:
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmd = New SqlCommand("Select * FROM client_details", con)
con.Open()
myDA = New SqlDataAdapter(cmd)
myDataSet = New DataSet()
myDA.Fill(myDataSet, "client_details")
DataGridView1.DataSource = myDataSet.Tables("client_details").DefaultView
End Sub
-->Now I am filtering this "client_details" table by this function:
Sub filter_client()
cmd = New SqlCommand("SELECT * FROM client_details WHERE Date = '" + fordate + "'", con)
myDA = New SqlDataAdapter(cmd)
myDataSet = New DataSet()
myDA.Fill(myDataSet, "client_details")
DataGridView1.DataSource = myDataSet.Tables("client_details").DefaultView
End Sub
-->Now what I was trying, is to add the above filtered rows in another Table "final_client" which I already created (From database explorer) with 2 columns only, "Name" and "Age".
In Form2, I have Datagridview2, which I want to populate with the above filtered rows.
My code in Form2 is :
Public Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmd = New SqlCommand("Select * FROM final_client", con)
con.Open()
myDA = New SqlDataAdapter(cmd)
myDataSet = New DataSet()
myDA.Fill(myDataSet, "final_client")
DataGridView2.DataSource = myDataSet.Tables("final_client").DefaultView
End Sub
Can You please let me know which part of Your code has to be placed in my code, I mean since I already created the 2nd table with columns, Name Age, then is it necessary to create a new datatbale "dt" as You created at the beginning of Your code?
I understood your code, just want some more clarification from You once You go through my code.
Thanks.
|
|
|
|
|
This looks very convoluted.
It seems that you select all the data from the table in the form load event and show it in a DataGridView. Then you have a sub: Sub final_client that returns a range of results according to a date variable but then attempt to call this sub in a sql satement cmd = New SqlCommand("SELECT * FROM final_client) .
This code will write the final_client data back to your Access DB.
For Each dr As DataRow in myDataSet.Table("client_details").Rows
Dim name As String = dr("Name").ToString
Dim age As String = dr("Age").ToString
Try
con.Open
cmd = New SqlCommand("INSERT final_client(Name, Age) " & _
"VALUES('" & name & "','" & age "')",con)
cmd.ExecuteNonQuery
con.Close()
Catch ex As Exception
...
End Catch
Next
I dont use Access databases, and I definitely dont use your architecture...
I cant help you any more. I think I will now kill myself
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
|
|
|
|
|
Thanks Andy, I am able to populate it. Thanks For Your help.
|
|
|
|
|
Your welcome
I don't speak Idiot - please talk slowly and clearly
I don't know what all the fuss is about with America getting it's first black president. Zimbabwe's had one for years and he's sh*t. - Percy Drake , Shrewsbury
Driven to the arms of Heineken by the wife
|
|
|
|
|
Ok I have a WebBrowser object that has just finished loading a web page.
If the user clicks a link that opens up a pop-up is there any way to control that pop-up web page?
For example, open the pop-up in another WebBrowser instance?
All suggestions welcomed!
Thanks
|
|
|
|
|
Hi,
there is a WebBrowser.Navigating Event that occurs before the WB navigates; however the only action you can take there is cancel the navigation, I don't think you can change the web page or the destination.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
|
how can i hide sqlsever database. still allowing my application to connect to it. that is users cannot be able to view the db object with user name and password in the web configure. i have been using shema approach but is given a lot of deployment issue
|
|
|
|
|
Denying "View Database Definition" permission to the user might just do that. Not sure though.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Hi all.
I am creating a program in which I used an object of background worker for searching a group of files in pc.
I am getting problem while I am trying to cancle the worker.
The code I used in a cancle button is as below :
backgroundworker1.cancleasync()
but this code is not cancling work of backgroundWorker.
Suggest me how to cancle the execution of backgroundWorker whilw there is some pending work to be done.
Thanks.
Gagan
|
|
|
|
|
Why do you think it's not cancelled ? I believe that you need inside your thread to check periodically if the thread as requested it be cancelled. That may only be true of the backgroundworker class, but it's worth looking into.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Thanks Christian for your reply.
I continouly checking in my BackgroundWorker1_DoWork thread for its canclation but the same problem occurs.
Can you tell me some code to describe what should I do in my working thread to check for its cancelation?
Thanks.
Gagan
|
|
|
|
|
Well, I believe you need to set a property like SupportCancel for it to work at all. Then you need to check the Cancelled flag on every iteration. RunworkerCompleted is called when you cancel, so you may need to check for it there, also. Are you sure you don't just need to wait for the current file operation to end ? What is your DoWork code ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Have you looked at the documentation? it says things such as:
CancelAsync submits a request to ... (*)
When you call CancelAsync, your worker method has ... (*)
Caution:
Be aware that your code in the DoWork event handler may ... (*)
(*) Sentences cut off to make sure you learn how to search.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Thanks to all of you guys
I have done the cancelation of my BackgroundWorker.
Thanks a lot.
Gagan
|
|
|
|
|
Hello every one
i kinda got my keyboard working here just have one question
how can i set the focus to whatever textbox selected or the text box that have the curser in it
Thanks everyone for you help and patients
Bob
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each ctl As Control In Me.Controls
If TypeOf ctl Is Button Then
If ctl.Text.Length = 1 Then
AddHandler ctl.Click, AddressOf btnKey_Click
End If
End If
Next
End Sub
Private Sub btnKey_Click(ByVal sender As Object, ByVal e As System.EventArgs)
TextBox1.Focus()
SendKeys.Send(sender.text)
End Sub
End Class
|
|
|
|
|
Hi again
The way I did it was, I made every textbox an instance of a derived class. I made my keyboard static. Whenever a textbox got the focus, it would pass itself to the keyboard ( which it could do elegantly, given that the class was all static ), and then you could also show the keyboard right away, if you wanted, on the basis that a textbox had been focused on. I also set up each textbox to know what the next textbox was, so you could use tab on the keyboard to jump between textboxes.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi
There is a problem that I want to display All employee records like treeview.
Such as:
MD
|
General Manager
|
------------------------------------------
| | | |
Production Finance Marketing Purchase
Manager Manager Manager Manager
|
--------------------------------------------
| | | |
Supervisor Incharge ABCD XYZ
Like above
Vijay Kumar S Pandey
Sector 3D, PitamPura
New Delhi
India
100034
|
|
|
|
|
Doesn't look like a problem to me. Looks like basic winforms code. We could do with knowing what your data source is, if you need help doing it. It would also help to see what you've tried. If you have no idea how to even start this task, perhaps you should pay someone to do it for you. Be careful if you place this job on sites like rentacoder tho, a lot of people bid on those jobs, even tho they are not programmers, then they post here and try to get us to do their paid work for them.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|