473,320 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Command Array Click Event in VB 2008

11
Hi All, I have created Command Array like follows.
Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Class Form1
  3.     Dim NewButton(25) As Button
  4.  
  5.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  6.         Dim loc As Integer
  7.         loc = 50
  8.         For i = 1 To 25
  9.             NewButton(i) = New Button()
  10.             NewButton(i).Text = "Hello " & i
  11.             Me.Controls.Add(NewButton(i))
  12.             NewButton(i).Location = New Point(10, loc)
  13.             NewButton(i).Name = "NewButton" & i
  14.             loc = loc + 20
  15.                    Next
  16.  
  17.     End Sub
  18.  
So.. I want to get each and every command button name when I press One of command button.

Ex:
If I press NewButton8 then I need msgbox with it's name, text (All of command button properties if possible). Button Name is very important

Thank You very much,
Regards,
Supun Silva
Oct 19 '09 #1
9 3646
tlhintoq
3,525 Expert 2GB
So what is your question exactly?
How do you make a message box?
How do you get the name of the button you clicked?
You seem to already have a handle on .Name property since you are assigning when you make the button. Just read it.
Oct 19 '09 #2
supun24
11
Please sorry........ I don't know what is the code I should write to get Button Name in msgbox and where put it???
Please help me...

Regards,
Supun Silva
Oct 19 '09 #3
tlhintoq
3,525 Expert 2GB
Take the .Name property of the button and put it into the .Text property of the MessageBox


Oh - wait - When you are making your buttons you are not assigning any handler to them. So they do nothing when you click them.

Make a handler to receive the .Click event of the buttons.

In your loop assign that handler to every button.
NewButton(i).Click += new handler (intellisense will help you out here)
All the buttons go tot he same handler so you will need to get the

((button)sender).Name property
Oct 19 '09 #4
supun24
11
Hi... Please could you kindly send me the coding including my code. I didn't understand your short code. Please forgive me for that..

Regards,
Supun Silva
Oct 19 '09 #5
tlhintoq
3,525 Expert 2GB
Have you ever created a button programmatically and assigned a handler to it?
Oct 19 '09 #6
supun24
11
No.. I didn't do the program to create button dynamically
Oct 19 '09 #7
tlhintoq
3,525 Expert 2GB
May I suggest that you start a little smaller then?
Instead of trying to create an entire array of buttons programatically start with just one.

Learn how to make one control (button) programmatically. Assign event handlers. Get properties etc.

Then when you are comfortable with how to do one, THEN try it with bunch of them.

We all have to learn to walk before we can run.
Oct 19 '09 #8
supun24
11
Hi.. Thank you buddy!!! Cool.. I really apologize about my knowledge. Could you kindly tell me how to create button in run-time(Dynamically) and add handler in vb 2008.

Thank you,
Supun Silva
Oct 19 '09 #9
tlhintoq
3,525 Expert 2GB
The MSDN is a great resource to start with for such things. I'm more a C# guy than VB - but it is still a .NET language so most everything is the same; only different.

MSDN on creating controls programmatically

MSDN for the button control (adding event handler for click)
Oct 19 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jim Mitchell | last post by:
I have the code snippet below. I fill a table of imagebuttons and would like to know which one was clicked to trigger the post back. Unfortunately, the Command event does not fire unless I load...
2
by: Chris Bolus | last post by:
I'm a teacher using MS Access on an RMConnect 2.4 network. On some workstations both I and my students sometimes get an error message when attempting to insert a command button on a form which...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
5
by: WhoopDing | last post by:
How do I handle all click events for all controls in Panel.Controls with one event procedure?
5
by: Varangian | last post by:
ImageButton ship; ship = new ImageButton; for (int i=0; i<5; i++) { ship.ImageUrl = pathofImage; ship.ID = "ShipNo" + i.ToString(); ship.Click += new...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
4
by: John Smith | last post by:
I have a continuous form. there is a command button with the following code for the OnClick event: DoCmd.OpenForm "frmPlants", , , "PlantsID =" & Me!PlantsID I click the button and frmPlants...
6
by: robusto33 | last post by:
Hi everyone, I'm really new to C#.net development, especially for win32 applications. I'm basically making a board game and was wondering if anyone could help me out with this predicament: I have...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.