|
|
Thanks for the prompt reply. I've now recovered from the heart failure that link gave me
Wish i'd bought a set of waders, i think i needed them.
But it did sort of answer one question i.e. the code in the link was aiming to show ALL connected devices and then find their ID's. I already know the device ID and its location so can i just hardcode for that one device on this specific pc and if so how do i get the data from it like i can if it's a serial port?
That code showed how to find the device but not how to 'talk' to it.
|
|
|
|
|
|
hahaha. Right, i'll take that as "it'll be easier to rebuild the old XP PC and use that".
Thanks anyway.
|
|
|
|
|
So I wrote this in SQL Linq for inserting a record. But I think I need a function in my DAL in order to add the record before saving it.
Using context As New CRMContext()
Dim pResults As New CRM_MESSAGES With
{
.Subject = sCM.m_Contact_Subject
}
context.SaveChanges()
So in my context, a class in my DAL DLL, I wrote a SaveChanges. do I need to write another function in order to insert the new row, and then save. Would this be an Overrides function? I looked for some samples, haven't found one yet. Having trouble using the right keywords for this.
Public Class CRMContext
Inherits DbContext
Public Sub New()
MyBase.New("DefaultConnection")
Database.SetInitializer(New CreateDatabaseIfNotExists(Of CRMContext))
Entity.Database.SetInitializer(Of CRMContext)(Nothing)
End Sub
Public Property CRM_MESSAGES As DbSet(Of CRM_MESSAGES)
Public Overrides Function SaveChanges() As Integer
ChangeTracker.DetectChanges()
'Call IPrepareForSave on entities that support it...
Return MyBase.SaveChanges()
End Function
|
|
|
|
|
Looked up DBContext, and added a couple of Imports to my Context
Imports System.Data.Entity.Infrastructure
Imports System.Data.Entity.Core.Objects
Not sure if that's what provided the Add Function, I would have to go back and remove the imports to figure that out.
but it was
context.model.add(new copy of model)
context.SaveChanges()
I moved the try catch around the Add and save, but I think I should just dump the Try and Catch all together.
|
|
|
|
|
I am new to vb .net and working on VS 2012. I have a datagridview which displays the rows of an ms-access 2007 database table. I created a form (with TeztBoxes and Add/Update/Cancel buttons - all dynamically (using the language)) which shows when a row of the datagridview is selected. So far, so good.
Now, I want the values of the fields (of the selected row) to be displayed in the textboxes and any changes made to the textboxes to be added/updated in the database, depending upon the button clicked. How can it be done? That is, how to: 1. Fill in the textboxes with row values, and, 2. Update/Add the changes to the database?
Basically, the REAL PROBLEM is REFERENCING the dynamically created controls on the form! I am getting nullreferenceexceptions! Please help!
Many thanks!
|
|
|
|
|
So.... you have a problem with your code and expect that we can see your code somehow and tell you what is wrong with it?
You can lead a developer to CodeProject, but you can't make them think.
The Theory of Gravity was invented for the sole purpose of distracting you from investigating the scientific fact that the Earth sucks.
|
|
|
|
|
I am sorry indeed! I didn't post the code as it is quite long. However, I have shortened it to a good extent now.
Here is my code:
====================================================
Private Sub DGVClients_RowHeaderMouseClick(sender As Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DGVClients.RowHeaderMouseClick
MessageBox.Show("You have selected row No. " & e.RowIndex.ToString())
Dim txtClientId As New TextBox
With txtClientId
.Size = New System.Drawing.Size(150, 20)
.Location = New System.Drawing.Size(150, 20)
End With
Dim txtClientName As New TextBox
With txtClientName
.Size = New System.Drawing.Size(150, 20)
.Location = New System.Drawing.Size(150, 45)
End With
Dim txtClientAddress As New TextBox
With txtClientAddress
.Size = New System.Drawing.Size(200, 20)
.Location = New System.Drawing.Size(150, 75)
End With
Dim lblCId, lblCName, lblCAdd As Label
lblCName = New Label
lblCId = New Label
lblCAdd = New Label
With lblCId
.Text = "Client Id:"
.Font = New Font("Arial", 12)
.Location = New System.Drawing.Size(20, 20)
.Show()
End With
With lblCName
.Text = "Client Name:"
.Font = New Font("Arial", 12)
.Location = New System.Drawing.Size(20, 45)
.Show()
End With
With lblCAdd
.Text = "Client Address:"
.Font = New Font("Arial", 12)
.Location = New System.Drawing.Size(20, 75)
.Show()
End With
Dim btnAddC As Button
btnAddC = New Button
With btnAddC
.Text = "Add Client"
.Font = New Font("Arial", 10)
.Size = New System.Drawing.Size(100, 35)
.Location = New System.Drawing.Size(20, 260)
End With
AddHandler btnAddC.Click, AddressOf Me.AddNewClient
Dim curForm As Form = New Form
With curForm
'Definition of the form
.Text = "Add / Update Client"
.Size = New System.Drawing.Size(400, 350)
.StartPosition = FormStartPosition.CenterScreen
.Show()
.Controls.Add(lblCId)
.Controls.Add(txtClientId)
.Controls.Add(lblCName)
.Controls.Add(txtClientName)
.Controls.Add(lblCAdd)
.Controls.Add(txtClientAddress)
.Controls.Add(lblCCity)
.Controls.Add(btnAddC)
End With
End Sub
Friend Sub AddNewClient(ByVal sender As System.Object, ByVal e As System.EventArgs)
'MessageBox.Show("Button AddClient clicked!")
MsgBox(txtClientId.ToString)
End Sub
=======================================================
It is the "Sub AddNewClient()" that I am struck up in. The controls of the created form are inaccessible in the buttonClick event handling sub. Also, if I DirectCast the controls, nullrefernceexception is thrown.
I appreciate if you could please sort it out for me.
Many thanks!
modified 12-Jul-15 2:32am.
|
|
|
|
|
I would suggest the following :
1. : I would not use the RowHeaderMouseClick - better use the CellClick-Event
2. : For editing I prefer a Dialog - perhaps startet by a ContextMenue or by right MouseButton in combination with the CellMouseClick-Event. In this Dialog you could manipulate the Cell-Values you want and write it back with a Button-Click. Inportant : every time you know which row/column you are acessing ...
3. : to add a new Entry I prefer a similar way like decribted. Perhaps you start this also by a ContextMenue or with an external Button - but the data is entered inside a Dialog. With closing the Dialog you decide by Button-Click what should happen with the entered data ...
|
|
|
|
|
@Ralff Meier
Could you please post some "code" (example) for it? Better still, if you could please modify my code as stated above. Thanks.
|
|
|
|
|
Are you familiar with creating Dialogs ?
I could guide you in creating what is necessary.
At first :
- a Dialog is a Form. On this Form you have placed the TextBoxes as needed by yourself. On the bottom of the Form (for example) you place 2 Buttons ("Accept Changes" and "Abort"). This Dialog also has Properties, with which you give the necessary data from the calling method to the Dialog (and back again). With the 2 Buttons you give a DialogResult to the calling method which says, that the changes are valid (or not).
Then :
The calling method (performed by your Click-Event) instances the Dialog, gives it the necessary data and shows it. When finishing the Dialog you get your DialogResult which tells you, if the data has to be written back or what else.
I prefer, that you first start by yourself and I help when Help is needed ...
I think, the first steps (creating the Dialog) could be gone by you ...
|
|
|
|
|
Sorry Ralf, but I haven't yet worked on Dialogs. However, I would try it once this issue is resolved. I can't start it afresh as the existing code I am working upon is quite huge for me to handel at the moment!
If you could please suggest an edit for my EXISTING code, it would be of great help! Thanks again!
|
|
|
|
|
It's very difficult for me to do that with your code - there a so many things missing, what a necessary. That's the reason why I made my Suggestion.
When you create a Button you also have to create an Eventhandler for the Button-Action. Each dynamcly created control (and also the handlers) must be dynamicly removed/disposed when finishing.
I seriously suggest you to think over the way, you are working/developing.
Why don't you try what I have suggested (before doing nothing) ?
|
|
|
|
|
Sure I would give it a try, however, it would take some time as I am preoccupied with some other assignments at the moment. Would get back for more suggestions/discussion once I am done. Thanks for the help.
|
|
|
|
|
No matter ... you are welcome.
If you want to go further you know where to find me ...
|
|
|
|
|
Hello,
I have sershed long time to fix a flickering when I'm open a Mdi forms and I found that code
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H2000000
Return cp
End Get
End Property
but the problem is when I'm trying to moving my form it was a very lagging happen or zigzag in my form it moving a very slowly.
Thanks
|
|
|
|
|
Instead of that hard to read code, why not use the "double buffered" property of the form?
How many controls are on there? Images? Yes, how big?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I'm not using images Just use textbox, Combobox and group box a lot of it, and I already used Double Buffered but it's not fixed my problem All I need a code to fix a lagging in form when I'm trying to move it manually.
|
|
|
|
|
Mohamed Hamdy wrote: I need a code to fix a lagging in form when I'm trying to move it manually. Unfortunately there is not a simple code solution to the problem. You have to take into account the number of different controls on the form, the speed of the processor and video card, and available memory space. Double buffering helps to reduce the problem, but when dragging a complex Window/Form across the screen there are still many repaints to be done as it moves.
|
|
|
|
|
Hello !
If the sql server is on my office's server , and I'm outside , is there any chance to connect to my database using my vb.net program ?
( the server doesn't have a real ip , but a dynamic ip from ISP ).
Thank you !
|
|
|
|
|
If the TCP/IP address changes I take it the name still stays the same? If that is the case then use the DNS name instead of the IP address in the connection string for the server. Of course you need to have a type of a connection that allows you to communicate with the inside network.
For the connection string format refer to https://www.connectionstrings.com/sql-server/[^]
|
|
|
|
|
Sorry , I'm not speaking for a website or a webserver. The server is on my office. In the office I use a ADSL internet connection that use a dynamic IP address. For what "Name" do you speak ?
|
|
|
|
|
So from what I gather, the database server has a fixed IP address inside your network but the IP address for your office that is shown from outside is changing? If that's correct, I believe that you need to contact you ISP and ask if you can get a fixed address etc.
The naming I'm referring to is DNS[^]
|
|
|
|
|
yes you're correct.
Even the ip from ISP is fixed , it's still an static ip address inside the ISP. So it's not a real ip address.
|
|
|
|