This is what needs to be done.
This project / assigenment will maintain a list of movie titles in an array. The user can add and remove movie titles from the list, clear and print the list.
The form will contain a combo box initialized with the following entries: A Dependent's Pay, An American Resident, Dancing With Fools, Home By Yourself, and Ghost Man.
There will be six buttons on the form. An add button that will add an entry to the list using an input box. The user may not add a duplicate title to the list. A remove button that will remove the selected item off the list. An error is displayed if the user tries to add a blank title or remove a title without first selecting one. A clear all button will remove all the entries from the list. A count button will display in a message box the number of movie titles can be displayed. The print button will display the ‘Movie List’ report in a print preview window. Include your name on the report. And finally, an exit button.
This is what I have so far:
Public Class frmlist
Dim movielist(100) As String
Private Sub ExitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub frmlist_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
movielist(0) = "A Dependent's Pay"
movielist(1) = "An American Resident"
movielist(2) = "Dancing With Fools"
movielist(3) = "Home By Yourself"
movielist(4) = "Ghost Man"
cboxlist.Items.AddRange(movielist)
End Sub
Private Sub AddToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles AddToolStripMenuItem.Click
movielist(5) = InputBox("Enter a movie title: ", "Movies")
cboxlist.Items.AddRange(movielist)
End Sub
End Class
Related
My DataGridView have some columns I want to turn a different color to indicate that they are auto-fill columns and does not need user input.
So I created the code to color columns:
Private Sub autocolumn()
Dim auto_cell As New DataGridViewCellStyle
auto_cell.BackColor = Color.LightSteelBlue
ProjTable.Columns(3).DefaultCellStyle = auto_cell
ProjTable.Columns(5).DefaultCellStyle = auto_cell
ProjTable.Columns(9).DefaultCellStyle = auto_cell
ProjTable.Columns(10).DefaultCellStyle = auto_cell
End Sub
And then place it into form Load event
Private Sub projectentry_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
autocolumn()
End Sub
On testing the form, the first row is colored no problem. Issue is on the 2nd row the color is white. Then the 3rd row its colored, and thee following white. And it follows this repeated pattern.
I even tried to make a DataGridView Rows Added event to call the sub
Private Sub color_load() Handles ProjTable.RowsAdded
autocolumn()
End Sub
Again same result. What may be the problem here?
I am making a risk-type game for school that dynamically creates a 4x4 grid of buttons inside a table layout panel in visual basic. I have successfully created the panel and buttons with names that correspond to the row and column of the button. There are also two parallel arrays - one for button owner and the other for button number - that correspond to the owner of the button and the number of "armies" in the button. My issue is that when the user clicks a certain button, I need to reference the button name/value to know how many "armies" the button has to control the "attack" portion of the player's turn.
The following code creates the table layout panel and the buttons with names.
'Create table Dynamically
Dim ColCount As Integer = 4
Dim RowCount As Integer = 4
Dim f As New System.Drawing.Font("Arial", 15)
riskTable.AutoScroll = True
riskTable.Dock = DockStyle.Fill
riskTable.ColumnCount = ColCount
riskTable.RowCount = RowCount
For rowNo As Integer = 0 To riskTable.RowCount - 1
For columnNo As Integer = 0 To riskTable.ColumnCount - 1
Dim buttonname As String
buttonname = "B" & rowNo & columnNo
Dim button As Control = New Button
button.Size = New Size(179, 100)
button.Name = buttonname
button.Text = "1"
button.ForeColor = Color.White
button.Font = f
AddHandler button.Click, AddressOf buttonname_Click
riskTable.Controls.Add(button, columnNo, rowNo)
Next
Next
Me.Controls.Add(riskTable)
This is the dynamic event handler that I created. I tried using 'Me.Click' to get the name of the button, but it only returns the name of the form. I need to have code in here that references the name of the currently clicked button to then in turn reference the box owner and box number arrays.
Private Sub buttonname_Click(sender As Object, e As EventArgs) Handles Me.Click
MessageBox.Show(Me.Name)
End Sub
Any help would be greatly appreciated! I think that once I get this working, the rest of the game will be pretty simple to figure out.
Thanks!
Put the name in 'button.Tag' instead/also:
button.Tag = buttonname
Then it is easy to get the name with:
Private Sub buttonname_Click(sender As Object, e As EventArgs) Handles Me.Click
Dim result As String = CType(CType(sender, System.Windows.Forms.Button).Tag, String)
End Sub
(Check the System.Windows.Forms.Button though, might need some tweak to match your buttons inside the table. riskTable.Controls.button ?)
I am new here. So apologize in advance if not wording question properly.
I am developing an application (VS2013, Visual Basic) that using multiple menu items in the MenuStrip. When item is clicked the identical function is called - the Tab is created and appropriate form is loaded.
i.e.
Private Sub XXXMNU0039_Click(sender As Object, e As EventArgs) Handles XXXMNU0039.Click
Dim f1 As New frm_B05_01_SalesQuotes
Dim imgnm As String = "XXXMNU0039"
Call XXXTabPages("Sales Quotes", f1, imgnm)
End Sub
Private Sub XXXMNU0040_Click(sender As Object, e As EventArgs) Handles XXXMNU0040.Click
Dim f1 As New frm_B05_03_SalesQuotesReports
Dim imgnm As String = "XXXMNU_Reports"
Call XXXTabPages("Sales Quotes Reports", f1, imgnm)
End Sub
....
I am wondering is there is a way to create a "global" default "on click event" for all menu items that will accomplish the same thing by default. I have all the relevant information for each menu item stored in a table and hope to avoid creating "on click" for each item.
Thanks in advance.
You could have the same handler for the click event of your ToolStripMenuItems.
Just add, after the first Handles XXXMNU0039.Click the event to handle for another ToolStripMenuItem and so on
Oviously, then problem is how to differentiate the various ToolStripMenuItem that calls the same event handler. But in the event arguments there is the Sender object that represent the current ToolStripMenuItem that has called the event.
Just DirectCast to a ToolStripMenuItem and read its name to pass the correct parameter to the XXXTablPages method
Private Sub menuItemHandler_Click(sender As Object, e As EventArgs) _
Handles XXXMNU0039.Click, XXXMNU0040.Click
Dim f1 As New frm_B05_01_SalesQuotes
Dim itm = DirectCast(sender, ToolStripMenuItem)
Dim imgnm As String = item.Name
Call XXXTabPages("Sales Quotes", f1, imgnm)
End Sub
I've got a problem that involves, on a button click event, changing the text of the currently selected textbox on the form. Is this possible? If so how do I go about doing it?
EDIT: I do not know the name of the textbox, but it will always be the currently selected or 'focused' textbox.
The main problem is that when you press the button, the Textbox is no longer the focus.
By solution appears here, You can do this:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If lastTextBoxFocused IsNot Nothing Then
lastTextBoxFocused.Text = "Bla bla, bla!"
End If
End Sub
Dim lastTextBoxFocused As TextBox
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'find all TextBox's in the Form.
For Each Ctrl In Me.Controls
If TypeOf Ctrl Is TextBox Then
'attach a lambda expression to each Enter event, to "remember" the last enter
AddHandler CType(Ctrl, TextBox).Enter, Sub(o, ev) lastTextBoxFocused = o
End If
Next
End Sub
I'm trying to page and sort my DataGrid which is inside a ModalPopupExtender but I can't page it in any way, already tried with <Triggers>, put the UpdatePanel inside, outside, in the middle, and it does NOT work. Modal popup does not get closed but the grid just disappears. Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Private Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
SqlServerDS.SelectCommand = "SELECT * FROM emp WHERE name LIKE '%" & txtSearchName.Text & "%'"
BindData()
End Sub
Private Sub BindData()
grdSearch.DataSource = SqlServerDS
grdSearch.DataBind()
End Sub
Private Sub grdBuscaPaciente_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdSearch.PageIndexChanging
grdSearch.PageIndex = e.NewPageIndex
BindData()
End Sub
Inside the Designer, this is the code h:
<modalpopupextender>
</modalpopupextender>
<panel>
<updatepanel>
<gridview>
</gridview>
</updatepanel>
</panel>
Tommy is right, so what you just have to do is re-show the popup.
After the BindData() in the PageIndexChanging event show the panel again with the Show() method of the popup extender.
This code is in c# but is pretty much the same.
gvHorarioPB.DataSource = (DataTable)Session["Prueba"];
gvHorarioPB.PageIndex = e.NewPageIndex;
gvHorarioPB.DataBind();
//mpePB is my modalpopupextender
this.mpePB.Show();
If you are using the .NET AJAX toolkit, keep in mind that each time you click someting (paging, sorting, etc.), the page performs a postback, even if it looks AJAX-y. Meaning that you will need to rebind the data each time. Try removing the IfPostback in your page load and see what that does for you.