|
Thanks Andy works perfect now
Bob
|
|
|
|
|
My pleasure.
A little tip, when there is a green line under something, hover your mouse over the text and the intellisence will give you a hint as to what is wrong.
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
|
|
|
|
|
Also, 2 things just for your information:
1. like Andy_L_J already implied, you should use a function when you want the code to return some value. For example:
MsgBox("Half of 11 is " & Half_Is(11))
Private Function Half_Is(ByVal MyNumber As Double) As Double
Return MyNumber / 2
End Function
Otherwise use a sub.
2. When you write a function or sub, you do not need to explicitly tell the code to exit the function or sub at the end, nor in the catch clause (that is why you got the green squiggly line). Your code will exit there anyway.
Use Exit Function or Exit Sub somewhere in the middle, and only when you don't want the rest of the function's or sub's code to be executed.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Thanks Johan
that help me out i apreciater that
to bad your at the other end of the world or i would buy you a beer
Thanks
Bob
|
|
|
|
|
No problem, if I would have liked beer, you could have sent it to me
My advice is free, and you may get what you paid for.
|
|
|
|
|
Thats to bad you dont drink beer
i could send you some canadian whisky hehe
do you know if this post is about me ???
Re: Stupid remarks by stupid people who are an MVP
i was just going to add a new post not sure if i shold now
or maybe you will know i want to have a form animated press a button and the
forme will slide up for the bottom of the screen and press the button agine and it will slide down
Thanks agine for your help
Bob
|
|
|
|
|
The stupid people post was not about you, don't worry. The guy was not talking about the people asking questions, but about the people answering them.
As far as I can tell, your questions have been good so far.
Making a form slide in or out of view should be possible, but where will you put the button?
You better post a new question about it, because I am not sure I can help you with this one.
My advice is free, and you may get what you paid for.
|
|
|
|
|
ok good i was woried about that for a sec
i got the animation figerd out google helped me
it was pretty easy
are you going to give me your adress so i can send you some canadian Whisy hehe
Thanks
Bob
|
|
|
|
|
I'll tell you what, I'll drink one to your health on my side of the globe, and we'll call it even
My advice is free, and you may get what you paid for.
|
|
|
|
|
Dear All,
I have one query regarding copying items from a datagridview into another. It is as follows:
I have two forms, Form1 and Form2.
In Form1 I am doing following :
I have a datagridview1, which has 4 columns, "Name", "Age", "Salary", "Date" .
I Filtered this datagridview1 by "Date" and count the number of rows, say e.g. 10 rows.
What I want:
In Form2 :
I want to get those filtered rows and populate them in other Datagridview2 in Form2.
Also, I want to select only "Name" and "Age" column from Form1 Datagridview1, and populate into
Datagridview2 of Form2.
Overall, out of 4 columns in Datafridview1, I want to populate Datagridview2 of Form2 with Filtered Rows and with only two columns, say only "Name" and "Age".
Hope My query is clear, Kindly suggest me how to proceed with this.
Thanks and Regards
R.S.
|
|
|
|
|
<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
|
|
|
|
|