|
Like I said before:
You can create an array of buttons. An array is a list of objects.
To do this, you add brackets '[]' when creating a variable, i.e button variable or integer variable.
int [] myInts = new int[2].
for(int i = 0; i < myInts.Length; i++)
myInts[i] = some integer value.
As for the code you need, you can do this:
int totaal = this.aanbodTableAdapter.CountFrisdranken().Value;
Button []buttonList = new Button[totaal];
for (int i = 0; i < buttonList.Length; i++)
{
buttonList[i] = new Button();
button[i].Text = aanbodTableAdapter.GetFrisdranken().FindByid(i).ToString();
}
You'd also have to set the location for your new buttons, so there's plenty of neccessary code missing here. But it should give you an idea of how to create a dynamic array consisting of buttons.
Have you concidered using a ComboBox instead? Might be hard to place 100 buttons on a form.
I.e add a combobox to your form in designview and call it myComboBox.
int totaal = this.aanbodTableAdapter.CountFrisdranken().Value;
ArrayList listItems = new ArrayList();
for (int i = 0; i < totaal; i++)
{
listItems.Add(aanbodTableAdapter.GetFrisdranken().FindByid(i).ToString());
}
myComboBox.DataSource = listItems;
-Larantz-
-- modified at 16:47 Wednesday 3rd May, 2006
|
|
|
|
|
Allready enormous thanks!
The reason why i don't use a listbox (i used one) is that it is some sort of cash register and a listbox is far from handy.
With this code:
int totaal = this.aanbodTableAdapter.CountFrisdranken().Value;<br />
Button []buttonList = new Button[totaal];<br />
<br />
for (int i = 0; i < buttonList.Length; i++)<br />
{<br />
buttonList[i] = new Button();<br />
button[i].Text = aanbodTableAdapter.GetFrisdranken().FindByid(i).ToString();<br />
}<br />
It still gives an error that the name "button" doesn't exist ..
I don't really get the part of the location of the buttons what you bring forward ..
I'm pretty new with these things ..
|
|
|
|
|
That code fails because you used 'button[i]' instead of buttonList[i].
button[i].Text = aanbodTableAdapter.GetFrisdranken().FindByid(i).ToString();
should be replaced with
buttonList[i].Text = aanbodTableAdapter.GetFrisdranken().FindByid(i).ToString();
An array of buttons is like, uhm, a series of buttons. So you can't access the array directly as if it was a button. You must identify the specific button in the array that you want to use, by an identifier. In this case we identify it by the integer 'i'.
So when defining
private System.Windows.Forms.Button []myButtonList = new Button[totaal];
you need to identify each of the buttons when you use them.
int totaal = 3;
private System.Windows.Forms.Button []myButtonList = new Button[totaal];
myButtonList[0] = new Button();
myButtonList[1] = new Button();
myButtonList[2] = new Button();
myButtonList[0].Text = "Button1"
myButtonList[1].Text = "Button2"
myButtonList[2].Text = "Button3"
or even easier with for loop:
public class foo : System.Windows.Forms.Form
{
private System.Windows.Forms.Button []myButtonList = new Button[totaal];
private void InitializeButtonArray()
{
for(int i = 0; i < totaal; i++)
{
myButtonList[i] = new Button();
myButtonList[i].Location = new System.Drawing.Point(10 + i*10, 10);
myButtonList[i].Dock = System.Windows.Forms.DockStyle.Left;
myButtonList[i].Name = "Button" + i;
myButtonList[i].TabIndex = i;
myButtonList[i].Text = "Text from your table";
myButtonList[i].Click += new System.EventHandler(this.myButtonList_Click);
}
}
private void myButtonList_Click(object sender, System.EventArgs e)
{
}
}
-Larantz-
|
|
|
|
|
I tried the code now to be sure that it doesn't fail.
I couldn't get the buttons to show without a panel.
So, add a panel in Design View. Set Dock to 'Top'.
Then in Code View, inside the loop, add
"'panelname'.Controls.Add(myButtonList[i]);"
and they will show.
private void InitializeButtonArray()
{
for(int i = totaal-1; i >= 0; i--)
{
myButtonList[i] = new Button();
myButtonList[i].Location = new System.Drawing.Point(i*10, 10);
myButtonList[i].Dock = System.Windows.Forms.DockStyle.Left;
myButtonList[i].Name = "Button" + (i + 1);
myButtonList[i].TabIndex = i;
myButtonList[i].Text = "" + (i + 1);
myButtonList[i].Width = 25;
this.panelHeader.Controls.Add(myButtonList[i]);
myButtonList[i].Click += new System.EventHandler(this.myButtonList_Click);
}
}
You also need a working button_click event handler method.
private void myButtonList_Click(object sender, System.EventArgs e)
{
switch(((Button)sender).Name)
{
case "Button1":
MessageBox.Show((Button)sender).Name
break;
case "Button2":
break;
default:
break;
}
}
This code added 20 buttons on my form that all called the button_click event handler method, and I could identify the caller and perform actions.
-Larantz-
|
|
|
|
|
Hi .. i would like to get the handle to the top level window where the mouse is hovering ... whether it is hovering in MY application or another application.
Thanks for your time.
|
|
|
|
|
Try to use the api function WindowFromPoint:
[System.Runtime.InteropServices.DllImport("user32.dll")]<br />
static extern int WindowFromPoint(int x,int y);
Then you can get the handle of the window that is just below the (x,y) point in absolutes coordinates (relative to the top-left corner of the screen).
Pablo Hernandez Valdes
|
|
|
|
|
thank you, pablo ... that sounds like just what i am after
|
|
|
|
|
i have a report that has 2 sub-reports each take one parameter (@srvtel)
cust_history -------> @servtel
. maint --------> @servtel
. pacakage --------> @servtel
i set the parameters using this code
cust_history rptcust=new cust_history();
rptcust.SetParameterValue("@servtel",t1.Text);
rptcust.SetParameterValue("@servtel",t1.Text,"maint");
rptcust.SetParameterValue("@servtel",t1.Text,"pacakage");
when i try to open the report it gives me this message: index was outside the bound of the array
this problem accoure due to the lines concerning the sub-report when i romved them and tring to open the report it shows me a window requesting this 2 parameters i gave them to it and it is opened. so how can i set the paramters for sub report
|
|
|
|
|
Wasn't there at little utility that would clean out all the debug stuff before you backed your projects?
Tom
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
I need to call Business Object Reports from Windows C# application. It should invoke the BO using BO API from C# winform pass the login credential to the BO and invoke that report in windows application.
Does any one have idea how to achieve that or someone has already implemented this in their application.
thanks in advance
Share knowledge to enhance your learning
|
|
|
|
|
first design your report then add it to your project, add a CrystalReportViewer
rpt_cust rpt=new rpt_cust();
CrystalReportViewer1.ReportSource=rptcust;
CrystalReportViewer1.Refresh();
i hope that help
|
|
|
|
|
Hi Friends
I want to resize form slowly with timer control.
please notice below code :
<br />
Timer1.Interval=100;
Timer1.Enabled=true;<br />
<br />
private void Timer1_Tick()<br />
{<br />
if (Form1.Height <= 1000)<br />
Form1.Height += 50;<br />
}<br />
Now when i run the project, Form size change, but with flicks like seeng monitor on tv!!!
What should i do ?
|
|
|
|
|
You should enable double buffering on your form. Click here to see how.
--------------------------------------------------------
My portfolio & development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Hi-
<br />
private void BuddyList_AfterSelect(object sender, TreeViewEventArgs e)<br />
{<br />
if (this.BuddyList.SelectedNode.Parent != null)
{<br />
this.BuddyList_User();<br />
}<br />
}<br />
<br />
private void menuItem3_Click(object sender, System.EventArgs e)<br />
{<br />
<br />
if (this.BuddyList.SelectedNode.Parent != null) <br />
{<br />
MessageBox.Show (this.BuddyList.SelectedNode.Text);<br />
}<br />
}<br />
In my menuItem3_Click event I cannot access the selected node of my treeview which is called BuddyList. It throws an object reference error: Object Reference not set to an instance of an object.
However in the function above that in a BuddyList (Treeview) event I access the SelectedNode with no problem and I am not sure why.
When the treeview is rightclick a context menu is display, then when a user selects an option from the context menu the event menuItem3_Click above, needs to check to make sure that the selected tree node is a root node and then display a message box.
Any ideas?
Thanks,
Jon Scalet
|
|
|
|
|
When the context menu is popping up, is it selecting/deselecting the currently selected node? That's my best guess.
If you need to, you can always cache the selected node in a class variable and just use that.
That said, always code defensively. Check for nulls before dereferencing them is always a good practice, especially when you cannot guarantee its not null.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Here's whats happening a right click is not trigger the AfterSelect event in the treeview (hence there is no selected node) so you were right.
How would I trigger the After Selected with a right click?
Thanks,
Jon
|
|
|
|
|
You may need to create a class that inherits from the TreeView and code a public function ("RaiseAfterSelect", we'll say) that calls the OnAfterSelect protected method of the TreeView. Then when you want to raise the AfterSelect event, just call the RaiseAfterSelect method you just coded up.
Another way, of course, is to set the selected node of the treeview in code via treeView.SelectedNode = someNode;
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
how to embed a vedio file into a c# web form also a powerpoint into a c# web form
too important
walaa
|
|
|
|
|
You can embed video using a number of 3rd party libraries: Windows Media Player COM object, the Managed DirectShow libraries available on this site, and so on.
You can embed a PowerPoint presentation by adding a reference to the Microsoft Office PowerPoint COM object, I'd assume.
|
|
|
|
|
Hello all,
I wanted to run this by some other folks for a sanity check before I do it.
I have an application (written by a friend) that deals with a heirarchy of objects. Each of the objects in the heirarchy implements an interface called IValidation. IValidation exposes an event that indicates when the validation state of an object has changed, and also has a property called ValidationIssues, which is List<validationissue>. Each validation issue returned contains a description of the issue, the severity, and a reference to the object with the problem. I control this interface completely and it is not used anywhere else, so I can alter it as needed.
Currently, the application loads the object heirarchy into a treeview control on the left side of a form. Context menus in the treeview allow the addition and removal of items in the heirarchy. At the bottom of the form is a list box that contains a list of all the validation issues. The rest of the form is a property grid that allows you to edit the properties of the item selected in the treeview. Double-clicking on an item in the listbox will also bring up the associated object in the property grid.
When something happens that changes the validation state of any object in the heirarchy, an event is fired that works its way all the way back to the root of the heirarchy. The form listens for that event coming from the root object. When this occurs, the form pulls back the new list of validation issues, sorts it and binds it to the listbox.
Anyway, this approach is slowed (horribly) by a couple of problems:
1) The entire set of validation issues is rerun anytime something changes in any object in the heirarchy.
2) Each object's ValidationIssues property returns a List<validationissues>. If an object contains child objects, then the validation issues from those objects are added to the list returned using AddRange.
I was thinking of doing a few things to speed this up:
1) Caching. Each object should maintain its list of validation issues, instead of requiring them to be regenerated each time the property is accessed.
2) Better use of the list. Maybe I could add a method to the interface to allow passing in a List<validationissue> reference to cut back on the copying between lists.
3) Maybe I could extend the List<validationissue> class to make it so that it has a method for removing only validation issues from a particular object. Then, when I got a ValidationChanged event, I could just add the validation issues for that particular object.
Any thoughts?
|
|
|
|
|
Sounds like you know what to do. One thing I'd recommend is running the code under some performance profiler such as Ants Profiler[^] to see where the real slow parts are; from there you'll have a better idea of what needs to be optimized.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I agree with Judah, it sounds like you know what has to be done.
One thing that popped into my mind while reading your explanation is that you might want to add something to the validation logic which verifies that the validation issues need to be recalculated. Of course, I'm not sure if this technique is appropriate for whatever it is your app is doing. But if it isn't necessary to revalidate every time a property changes, perhaps it would be worth the extra effort to add a property to IValidation which returns true if the object actually requires re-validation, else false. It could cut down on a lot of unnecessary validation.
Just a thought...
Josh
|
|
|
|
|
Actually that functionality was already there, but wasn't being used. I never did implement the whole caching thing, but I fixed so that only the object whose validation state changed was updated. The performance improvement was very dramatic. I'll probably try the caching next to see if I can get it to be really snappy.
|
|
|
|
|
I have a tab control that is part of a spit container. The tab control is in the upper panel and in the bottom panel there is a help field that displays info\rules for the current item.
I would like to fire one generic event on the enter of each item of the tab control that will populate the help field from the item.tag. I was hoping to get away from having to have an Enter event on each of the items in the tab page (there are over 200 items on the tab page). I would like to have one generic method that would fire when the user navigates to a new item. It would need to determine the current item and and get the tag for the item and repopulate the help field.
Any ideas on how to implement this?
TIA
New C# Developer!
|
|
|
|
|
Write a recursive method which hooks the Enter event of every control on each tab page. All of the controls' Enter events are handled by the same method. In that handler you can update the help info in the bottom container.
Josh
|
|
|
|