473,499 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User control and dialog box VB.NET

115 New Member
I am working on a project that has a usercontrol lets say usercontrol1, and dialog box (dialogbox1)
in the usercontrol there is a list of cars with several other bits of info foe example, registration, colour etc etc, There is also an add button.

When the user clicks on the add button the dialogbox1 opens.

Dialogbox1 has several text boxes, This is to input a new car and the cars details. When they click on the add button i add this info to a database and close the form.

what i want to do is.....
Once the user clicks on the add button in the dialogbox1 is store the data to a datatable or a list and pass this back to the user control so i can append the item to the list. I think this is possible.

Other ways of doing it.
I could just repopulate the list from the database but this could cause the system to slow but i also do not know where (which event) i would put the call to repopulate the list

What i am having trouble with....
Passing the data from the dialog box1 to the usercontrol.

What i have so far ...
pretty sure that this gathers the data, now all i need to do is send this to the usercontrol on dialogbox1.close
Expand|Select|Wrap|Line Numbers
  1. Public Shared Function collectAppendingRow() As DataTable
  2.             Dim tmpList As New List(Of SortData.carInfo)
  3.             Dim tmpTbl As DataTable = Nothing
  4.  
  5.             tmpTbl.Rows.Item(0)(0) = Dialog1.MakeTextBox.Text
  6.             tmpTbl.Rows.Item(0)(1) = Dialog1.ModelTextBox.Text
  7.             tmpTbl.Rows.Item(0)(2) = Dialog1.ColourTextBox.Text
  8.             tmpTbl.Rows.Item(0)(3) = Dialog1.RegTextBox.Text
  9.             tmpTbl.Rows.Item(0)(4) = Dialog1.SpecTextBox.Text
  10.  
  11.  
  12.  
  13.             Return tmpTbl
  14.  
  15.         End Function
  16.  
i am using visual studio 2008
Nov 10 '08 #1
3 3828
nukefusion
221 Recognized Expert New Member
So, it sounds likes your user control is not databound to your database and what you want to do is upon clicking this "Add" button, open a dialog for adding a new car and when that dialog is closed, add that data to both the database and to your usercontrol? Is that right?

Is there any reason why you can't add a method to your UserControl called AppendItem or AddCar or something that takes a Car object or the seperate bits of information from the dialogs textboxes, i.e. Name, Model, Make as parameters?
You can the put some read-only properties into your custom dialog to provide access to the new cars information (or just change the modifiers of the textboxes on the form to make them visible outside of the form - looking at your sample it looks like this is what you have done at the moment?) and then put code similar to the following in the event handler for the "Add" buttons Click event?


Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
  3.         Dim frmMyDialog As Form ' <-- or your custom dialog type
  4.         If frmMyDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then ' user clicked ok button
  5.             ' Call user controls AppendItem method
  6.             .AppendItem(frmMyDialog.NameTextBox.Text, frmMyDialog.ModelTextBox.Text)
  7.         End If
  8.     End Sub
Nov 15 '08 #2
truezplaya
115 New Member
Sorry i had managed a work around by the time i recieved your reply but i m going to look in to your way of doing it maybe try using a collection Cheers
Nov 21 '08 #3
balabaster
797 Recognized Expert Contributor
Using a collection:

The first time the page loads, make the database call and populate a custom collection which holds instances of a class made to imitate a record in your table - this works just like a table would, but allows you a more typesafe way of accessing your data.

Your UserControl can then be programmed to bind to your custom collection rather than load from the database.

As an instance is changed or created in your dialog box, it can then save the changed/created instance to the database. If this was a new instance that was created, it can be added to your collection.

Have your UserControl rebind and it will re-render itself displaying the modified collection.

Using this method is less expensive than reloading the data directly from the database, however, you do have to worry about data concurrency...

The alternative (although more expensive) approach is to load from the database each time. This way there is less concern for data concurrency which can be a pain if you're not familiar with it...
Nov 21 '08 #4

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

Similar topics

1
8551
by: Marco Kunze | last post by:
Hi, when using user dialogfs in VBA I do not realy understand the dialog function actions. May anyone please explain me the actions 3 - 5? Thanks, Marco Function dialogfunc(DlgItem$,...
2
3033
by: Shane Molton | last post by:
I have a few user controls and I don't want to add them to the main form. I simply want to be able to spawn them like pop-up windows I added them to my project and call show(), but nothing...
2
3384
by: Samy | last post by:
Hi There, I have a user control with buttons on it which I use on a aspx page (parent page). On a button click, a modal dialog(aspx page) opens up and the user enters some info in the modal dialog...
1
1630
by: Shawn Eary | last post by:
Hello Everyone: I used VB.NET 2003 Standard to create a User Control which I named PersonControl and then overrode its OnLoad routine to use SQL commands to populate its sub-controls. When I...
0
1666
by: clintonG | last post by:
I applied aspnet_regsql to SQL2K which was working fine throughout Beta 2 development. After installing Visual Studio and SQL Express RTM my application has blown up. Logging in to the application...
0
1101
by: VivekR | last post by:
Hi I am writing a MFC dialog application in which i am inserting a .NET user control named WinUserCtrl. This .NET user control exposes the control by a class CfgnUICtrl which is derived from...
1
1539
by: randy1200 | last post by:
In Visual Studio 2003, I could create a new user control such as panel1. The name panel1 would appear in the toolbox under "My User Controls." I could drag this panel1 from the toolbox onto...
0
1237
by: diatom | last post by:
Hello, In a windows application, I just created a new custom user control. This custom user control is simply a dialog that I want to re-use. When my dialog opens, by default it is located in...
2
2023
by: Carl Johansson | last post by:
I'm trying to learn how to create a user control. As far as I can understand, Visual Studio contains a template named "Windows Control Library" to this end. However, this template is missing when I...
7
2904
by: Sin Jeong-hun | last post by:
I have a dialog form which pops up from the main window using the ShowDialog() method. this dialog has no or button, and it has quite a lot of controls on it. Now, I want to close this dialog...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.