Unbound Data Repeater Scroll Issue - vb.net

I Dragged a DataRepeater into my form.
Added a TextBox to the DataRepeaterItem.
Added A button to the form.
Wrote these 2 Lines of Code :
Private Sub Button1_Click(..) Handles Button1.Click
DataRepeater1.VirtualMode = True
DataRepeater1.AddNew()
End Sub
Run Project
Press Add Button
in the textBox Write "1"
Press Add Button
in the textBox Write "2"
Press Add Button
in the textBox Write "3"
Press Add Button
in the textBox Write "4"
Till Here Every Thing is Fine.
Then Scroll data repeater Up
"1" Changes to default TextBox1
Why Does it happen. How can I prevent it from happening.
Thanks in Advance.

The repeater control isn't going to hold all the values by itself. In virtual mode you don't have to use a datasource, but you have to use something. In this example, they used a simple Integer array: VB.NET Repeater Simple Data Binding Without Datasource

Related

How can I simulate a keyPress event on a combo box when I click a buton on the same form im MS Access

I'm creating a form in MS Access with 10 butons simulatin a numeric keypad (only the values 0..9).
I would like to change the value of a combobox control in a subform each time I click on one of these butons. The combo box control is named "projectID"
I tried this but it is not the same as pressing the same key on a keypad.
Private Sub Buton3_Click()
Call Me.frmServDedicacion_Subformulario.Form.projectID_KeyPress(51) 'Ansii code for 3
end sub
I put this procedure as keypress event in order to verifiy the combobox method is executed, and it does (msgbox is ok) but the combobox doesn't receive the KeyAscii value.
Public Sub projectID_KeyPress(KeyAscii As Integer)
MsgBox Chr(KeyAscii)
End Sub
This looks like a problem referring to a control on a sub form from the main form. I still have trouble getting this right so I use a cheat sheet:
http://access.mvps.org/access/forms/frm0031.htm
I created a main form called main and put 10 buttons named button0 - button9 on the form and I dragged a form called mysubform onto the main form to create a subform. mysubform has a textbox named projectID. Then just set the click event to button0 to:
Private Sub button0_Click()
Me!mysubform.Form!projectID = 0
End Sub
Don't forget similar click events for buttons 1-9
some things that may be helpful:
! is the bang operator see:
Bang Notation and Dot Notation in VBA and MS-Access
by default, when you drag a form to create a subform control on another form, access gives the subform control the same name as the dragged form. so here mysubform refers to the subform control and not the original form used to make the subform.
Then .Form gets the form wrapped by the subform control.
I hope this answers your question

Visual Basic Can't Type in Listbox

I am using Visual Studio and working in a Windows Form Application. I have added a Listbox on my form. The problem I am having is that when I run my application I can't add any text or even select the Listbox to put my cursor in.
You have to add values or action to listbox before run it,if you run it without value or action absolutely that will give you nothing.
To add a value in listbox,right click on listbox then select "edit items...".
Or you can make a action like : add text to listbox from textbox,do looping,or another...
From the design window from theToolbox add a TextBox and a Button to your form. (The ListBox is already there, right?) Enter the following code to your form in the code window.
'This is the code that runs when the users clicks the button
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'This is the code that copies the text in the text box to the list box
ListBox1.Items.Add(TextBox1.Text)
'This code clears the text in the text box
TextBox1.Text = ""
End Sub
The text in the gray window that appears in light gray and is preceded with an apostrophe are comments; not part of the code.
Now run the program and type in the text box. Click the button and the text you typed will appear in the list box. Now that you have had this brief introduction to Visual Basic . NET try searching for a beginners tutorial. Come back when you have some code that you wrote but doesn't turn out as you thought.

Make a button have multiple uses

okay... How do I explain this without being totally confusing?... Alright, I have this form that has MenuScripts (top-levels and second-levels). The problem that I am having is one of the second-levels is "Add" which brings you to another form when clicked. This other form has a button ("Record") and text boxes. This other form allows the user to input data and when the record button is clicked, the inputted data is written into a text file. Ok, so back to the first form. Another second-level MenuScript is "Update" which also brings the user to the other form; but first, the user has to click an item within a listbox to proceed. How do I get the data from the selected item to appear in the appropriate textboxes and how do I get the record button to update data instead of being confused and thinking it is only a add-data button?
Is there a way to use an "if" statement to say something like "if mnuAdd is clicked then" "elseif mnuUpdate is clicked then". Would something like that work for giving the record button multiple uses?
Also, if someone can give me some pointers on making sure the user selects an item within the listbox would definitely be a plus! Thanks, guys!
Unfortunately, I cannot add images since my reputation is too low.
Here is a visual representation of my ultimate goal
Easiest way: before displaying the second form set it's Tag property to something distinct – say "Add" or "Update" – depending on which menu item is selected. Then you just test the Tag value in the button's Click event and proceed accordingly.
As for determining whether a list item is selected: well if there isn't the ListBox's SelectedIndex property will be set to -1.
You need to put a public property on the second form (Details) which specifies which mode it is in. For instance, you could create a mode enumeration like this:
Public Enum EntryModes
AddBook
UpdateBook
End Enum
Then, define a public mode property on the second form, like this:
Public Property EntryMode As EntryModes
Get
Return _entryMode
End Get
Set(ByVal value As EntryMode)
_entryMode = value
End Set
End Property
Private _entryMode As EntryMode
Then, when you show the second form from the menu, just set the property first, before showing it:
Private Sub mnuAdd_Click(sender As Object, e As EventArgs)
Dim dialog As New DetailsDialog()
dialog.EntryMode = EntryModes.AddBook
dialog.ShowDialog()
End Sub
Private Sub mnuUpdate_Click(sender As Object, e As EventArgs)
Dim dialog As New DetailsDialog()
dialog.EntryMode = EntryModes.UpdateBook
dialog.BookToUpdate = ListBox1.SelectedItem
dialog.ShowDialog()
End Sub
As you can see, in the Upate menu click, I also added a line that passes the information for which book should be updated.

Dynamic Textboxes

I have a gridview - GridView1.
I am adding rows to this Gridview1 dyanamically through code.
One of the columns is a dropdownlist that reads from a sqldatasource.
The textboxes, dropdownlists & sql datasources are all arrays.
If I change the value of the dropdownlist, it maintains its state even after the page reloads on any button click event.
This is ok.
However, the values of the textboxes are not maintained.
Say I enter "Hello World" in the textbox & click "Add" button, I want to collect the text value in dropdownlist(which I can read) & the value in textbox(which returns blank.)
Please suggest a method so that on add button click I can retrive the value I had typed in the textbox.
Each textbox has a unique id & I tried using the ID to get its value
eg
protected Sub Add_Click(ByVal sender As Object, ByVal e As System.EventArgs) handles add.click
{
Dim valueinText = gettext(1).text
}
now if I type "Hello World" in textbox: gettext(1),
Reults:
valueinText = ""
Thanks in advance
You will have to reset the values for unbound textboxes that get their value from code when you post back. In your Page Load Event...
If Page.IsPostback Then
'Code that uses dropdownlistAtoZ.SelectedValue
'to fill in correct value for Textboxes.
End If
I was trying to create the same textboxes on every page_load event. But this just erased their values & their client_ID kept changing.
Instead, I tried making all textboxes Shared and created them only once on add click event, added them to a Row (which is again shared) and on page_load if page.postback = true I just added the row to the table again. If you don't do so, the row will not be shown on reload.
This solved my problem(now the values entered in Textbox were not cleared like before).
I accessed the value by classname.textboxname(i).text.
Now the solution seems obvious, but I spent a few days trying to solve this.
Thanks!

Clean way to display/hide a bunch of buttons based on a ComboBox selection

I'm writing a standalone application in VB.NET using Visual Studio 2005.
I want to display/hide a bunch of Buttons based on the selected value of a ComboBox. Each selection would have a different set of Buttons to display, and I'd like to have them arranged in a nice grid.
Driving a TabControl with the ComboBox value would be the kind of behavior I want, but I don't want it to look like a TabControl to the user because it might be confusing.
Is there a way to do this?
Basically, I'd like Selection1 of the ComboBox to show Buttons 1-4, Selection2 to show Buttons 5-11, Selection3 to show (maybe) Buttons 1, 3, 5, 6, and 8, etc., have them arranged nicely, and have the GUI show only the ComboBox and the buttons.
Thanks in advance as always!
Use a Panel control (or multiple if the items aren't grouped right next to each other) and set the visibility accordingly.
(Added)
You CAN stack panels on top of each other, so that the buttons all look like they're in the same location. but it becomes a maintenance nightmare and I don't recommend it.,
Hack warning - the following is a hack, but it works.
Another option is to use a tab control, but hide the tab buttons. (You can do this by positioning a panel over the buttons, but you have to be careful of letting the user resize the form.) Then you set the TabIndex based on the drop-down changing.
Edit again - added per comment
If you use the hack, you can add this into the ComboBox's selected index changed event....
(code may be wrong, as I'm not at my dev pc and can't check, but you get the idea)
TabControl1.SelectedIndex = ComboBox1.SelectedIndex
You could put all of your buttons on a panel on your form. Then when the SelectedIndex event of the combobox fires, you can loop through the buttons on the panel and turn them on and off based on their Tag property.
For this example you would set the Tag property of each button equal to the combobox index or indexes that you want it to turn on for. If you want it visible for more than one combo selection just comma seperate the index values in the tag property.
You don't have to key off of the combobox index. You could use the selected text for example. If you did that, just put the texts to show the button for in the tag property and change the code from ComboBox1.SelectedIndex.ToString to ComboBox1.SelectedText.
The buttons will turn on and off where they are placed at design time, but you could add some code here to arrange them dynamically as well so that all the visible buttons are neatly arranged.
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
For Each ctrl As Control In Me.Panel1.Controls
If TypeOf ctrl Is Button Then
If Array.IndexOf(Split(ctrl.Tag, ","), ComboBox1.SelectedIndex.ToString) > -1 Then
ctrl.Visible = True
Else
ctrl.Visible = False
End If
End If
Next
End Sub
Maybe using a FlowLayoutPanel will help you display the buttons.
You can use a jagged array to define which buttons belong to which combo-box item.