|
This works without a problem at my end (see my code below).
My only thought would be that you call this class before the datagridview is created.
The form has a datagridview on it called datagridview1 (original I know)
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dt As new DataTable()
dt.Columns.Add(New DataColumn("Col1"))
dt.Columns.Add(New DataColumn("Col2"))
Dim row As DataRow = dt.NewRow
row.Item("col1") = "col1"
row.Item("col2") = "col2"
dt.Rows.Add(row)
row = dt.NewRow
row.Item("col1") = "col11"
row.Item("col2") = "col22"
dt.Rows.Add(row)
DataGridView1.DataSource = dt
Dim temp As New Class1(DataGridView1)
End Sub
End Class
Public Class Class1
Public Sub New(ByRef dgv As DataGridView)
AddHandler dgv.UserDeletingRow, AddressOf mydelete
End Sub
Private Sub mydelete(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs)
MessageBox.Show("Eureka!!!!")
End Sub
End Class
This works perfectly for me.
When do you create the instance of the class?
|
|
|
|
|
Wow you reply fast, you're either in my time zone, or you never sleep!
That was EXACTLY my problem thank you very much! Funny thing is, I figured it out just before reading this post.
I instanciated the object globally, i.e. before the dataGridView existed, after moving the code to the Load (same as you did) it worked fine!
5!
|
|
|
|
|
evilnoodle wrote: Wow you reply fast, you're either in my time zone, or you never sleep!
A bit off the both (my average sleep a day is around 4 hours)
evilnoodle wrote: thank you very much
Your very welcome, glad to be off help where I can
evilnoodle wrote: I figured it out just before reading this post.
Even better you'll remember it longer that way
|
|
|
|
|
AddHandler pCloseCtrl.Click, AddressOf ClickHandler
Private Sub ClickHandler(pObj As Object, pArgs As EventArgs)
'your code here
End Sub
The current version of VB does not support multiline delegates, so it is not possible to use the anonymous function syntax.
To remove the event, you use the same syntax except you say RemoveHandler instead.
|
|
|
|
|
The entire code snippet converts very well to VB - the conversion is (via Instant VB):
Private Sub test()
AddHandler pCloseCtrl.Click, AddressOf AddressOf AnonymousMethod1
End Sub
Private Sub AnonymousMethod1(ByVal pObj As Object, ByVal pArgs As Object)
If Me.formIsDirty Then
MessageBox.Show("There are unsaved changes, please save the changes before closing.")
Else
pForm.Close()
End If
End Sub
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
VB & C# to Java Converter
Java to VB & C# Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: convert VB, C#, or Java to C++/CLI
|
|
|
|
|
Is there any example showing the use of serial port tool which is in the toolbox of vb.net? Don't know how it work even after i went to msdn.
|
|
|
|
|
hi,
You can surely find many online tips for writing the code..i am telling this becoz i am also working exactly with the same what you are expecting..My advice is, try yourself by searching in google so that you will get more ideas.
Regards...
Selva Shankar
|
|
|
|
|
I having some text files in a folder. I want to get all the files name and last modified date. how to get all files name and last modified date.
Jishith
|
|
|
|
|
Directory.GetFiles, from memory, then for each file, you would have to request the fileinfo to get the modified date.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I have One listbox in my form. I have to send multiple data from listbox to database as user select one or morethan one value. Also If i click on Refresh button all the selectecd valuue diselect
.
|
|
|
|
|
Refresh button ? Is that part of your question an ASP.NET question ?
If you have to store more than one value, then you need to set up your db to take more than one value for a field, through a joining table, or by storing XML or something.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
nO, tHIS IS NOT A PART OF ASP.NET.
I HAVE A FORM WHERE I HAVE PUT A LISTBOX. IT DEPENDS ON THE USER HOW MANY LISTITEMS HE SELECTS, AND DEPEND ON THAT TRUE VALE I HAVE TO EXPORT THOSE NAME TO DATABASE. IN MAY DATABASE THERE IS ONLY ONE COLUMN FOR THAT FIELD.
I CAN PASS ONE VALUE BUT NOT MORE THAN ONE.
CAN U GIVE SOME CODE TO HELP ME OUT OF THIS PROBLEM.
|
|
|
|
|
I hope the caps lock was an accident - it is rude to yell at someone trying to help.
If you can select many items from a list box and have only one field to store the data it in how do you propose to acheive it?
CG suggested you create a link table which is a standard relational database structure. Or you could store the list as XML in one field (also suggested).
You are not asking a programming question, it is a design issue. Decide on the design and then code it appropriately. If you are looking for code to CRUD the database then you need to look harder, there are many article here which will help you.
[edit]
Ok so you asked exactly the same question earlier about checkboxes, did you think the answer would change for a list box? Listen to what you are being told.
[/edit]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
As Mycroft said, hope the caps lock was an accident. Having the all caps is like shouting.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Yeh, It was by mistake i used the caps lock.
|
|
|
|
|
I have an assignment and I have been trying to get in touch with my professor to no avail. I missed last class and am totally behind. Any help would be appreciated. Here is the programming challenge:
Create an application that simulates a lottery. Should have an array of 5 integers and should generate a random number from 0-9 for each element in the array. The array is permitted to create duplicate values. The user should enter 5 digits which the application will compare to the numbers in the array. A form should be displayed showing how many of the digits matched. If all match, display a form proclaiming the user as the grand prize winner.
Thanx
|
|
|
|
|
Sounds really easy to me. Where are you stuck ? I don't see how I can give advice without telling you exactly how to do it. You create an array of 5 integers. You use a loop to specify values for all five using a random number generator. You ask for 5 numbers, then you check if those 5 are the five you have ( I guess you need to do some tricky stuff here, because duplicates are allowed ). Then you show a form at the end if they win.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thank you for the quick response. I am stuck with the array part of the problem. That is what I missed in class last week. I am new to programming and have very basic understanding of VB. I am not to great with loops either. Is there anything you can explain to me in layman's terms in regard to this program. Sorry I can't be more specific, I am in way over my head.
creelo
|
|
|
|
|
This is VB.NET, right ?
An array is a collection of objects, I am not sure of the syntax to create one in VB. I never use arrays because they are fixed size, I prefer to use a list. However, if you have an array of five objects, then they are accessed by index.
If n is your array, n(0) is the first int, and n(4) is the last one. So you create a loop, such as:
dim i as int
for(i = 0 to 4)
n(i) = i;
end for
This would assign the values of 0 to 4 to your five numbers.
Again, I don't do VB, so my syntax may be a little wrong, I'm doing the best I can
So, you will create an array of 5 ints. You will use a loop to assign random numbers to these values. He's allowing you to have duplicates to simplify the creation, you get a random number and you don't need to check if it's in there already. But, I would say the best way to check if the two sets are the same, is to iterate over both at once, and count how many times each of the 10 values is in there. If 0 is in the your lot twice, you need to count that it's also in the users selection twice, for example.
I would therefore create another array to store the users entry, to simplify the code that does the checking.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
creelo, I would suggest changing courses, if this is beyond you then you have a VERY steep learning curve in front of you.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: I would suggest changing courses
I second that. Not just changing courses but changing majors and career goals.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
This is how you create an array with ten items:
Dim lottery(9) As Integers
Now figure out how to change that so that it holds five items.
To create random numbers, create an instance of the Random class. The Next method is used to genereate a random number.
That should be enough to get you started. Once you get started you can ask more specific questions about your code, which is better suited for a fourm than a "how do I do my assignment" question...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Christian Graus wrote: Then you show a form at the end if they win
Let's not write redundant code now!
I had this project when I was 16 and programming in Turbo Pascal (what fun I had those days!) and even then we were told to compensate for duplicate values. Allowing duplicates makes the odds against winning almost infinte!
|
|
|
|
|
Thanks all for the help...ohh, and to Paul Conrad and Mycroft Holmes...the smarmy and brilliantly funny gentlemen who said I should switch majors and career goals. While I enjoy smugness as much as the next guy, I do not know why you would waste time writing such things if you were not going to help me with the question. For the record, I am an IT Helpdesk Support for a very good company, and I have a great amount of knowledge when it comes to computer software and hardware. I am not into programming but I did want to try it to see if I would like it.
I appreciate the concern and all, but I am not a programmer nor do I desire to be one. If you went on my website to find out how to fix your computer, I wouldnt bash you because you dont know something...but I am sure you two know everything anyway. You are knowledgable in every aspect of life. Two geniuses, trying to top the other.
Did that raise your self-esteem a little? I hope so...
|
|
|
|
|
Does anyone have any simple application on communicating with external device via virtual com port?
|
|
|
|