|
I'm assuming that your datagridview controls are datatable driven. If so, you can create a default view from the product search table while setting a rowfilter on the check box column. Then set the datasource table of the quoteline datagridview equal to this default view.
|
|
|
|
|
I'm not sure, but I don't think what u are suggesting is quite what i am looking for.
what i am looking for is the vb.net syntax for how to do something like this:
dim aricleid as integer
dim productname as string
dim productprice as string
select
articleid,
productname,
productprice
from productsearchform.datagridview
where checkboxcolumn.checked=true
insert into quoteline.datagridview
articleidcolumn,
productnamecolumn,
productpricecolumn
with values (get the declared values from above code)
articleid,
productname,
productprice
continue to next row until all rows on the on the productsearch datagrid that have been checked have been inserted as new rows in the quoteline datagridview.
Is there a good way to do this?
|
|
|
|
|
Assume for example,
productsearchform.datagridview.datasource = datatableproductsearchform
quoteline.datagridview.datasource = datatablequoteline
Try this approach:
datatableproductsearchform.defaultview.rowfilter = "checkboxcolumn = true"
datatablequoteline = datatableproductsearchform.defaultview.totable
Or this approach:
Add this code to productsearchform.datagridview selectedindexchanged event
if productsearchform.SelectedRow.Cells.Item(0).Text = true
dim datarownew as datarow
datarownew = datatablequoteline.newrow
'use the following code to populate the fields, one per field in datatablequoteline
datarownew.item("[field name]") = productsearchform.SelectedRow.Cells.Item(1).Text
datatablequoteline.rows.add(datatownew)
end if
|
|
|
|
|
Hi Dptalt,
The last approach seems to be what I have been looking for. I'll give it a shot later today. Appreciate your help.
best regards,
Hans
|
|
|
|
|
My form has a TabControl with 4 tabs. The user fills out information on each tab. When the user tries to change to a different tab I validate the information on that tab first. The validating code is in the TabControl.Leave event. If the information the user enters is not valid I have a messagebox popup that says the information needs to be corrected. If this occurs it still goes to the new tab the user clicked on. How can I code it so that it stays on the current tab until the information is valid? Can I cancel the event so that it does not go to the new tab?
|
|
|
|
|
In this event put your msgbox and validation routine call
Private Sub TabControl1_Selecting(ByVal sender As Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Selecting
'validate
'msgbox
e.Cancel = True '<- ignores tab change event
End Sub
|
|
|
|
|
HI,
I need to get the Serial number of an Xp Machine and if possible the Hard Disc Details... I tried using query to Win32_PhysicalMedia, but not able to get details about the SerialNumber and Hard Disc details..
can anyone help me in this....
Code which i tried:
Dim strSN As String = String.Empty
Dim strQuery As String = "SELECT * FROM Win32_PhysicalMedia "
Dim query As ManagementObjectSearcher = New ManagementObjectSearcher(strQuery)
Dim queryCollection As ManagementObjectCollection = query.Get()
Dim mo As ManagementObject
For Each mo In queryCollection
If mo("SerialNumber") = Nothing Then
strSN = "None"
Else
strSN = mo("SerialNumber").ToString()
Exit For
End If
Next
Regards,
Anas
|
|
|
|
|
You've missed an important detail. You need to specify a scope, or which WMI namespace you want to search and which machine to search. In the example below, that period in the scope string specifies the local machine:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Important!! MUST use \root\cimv2 here! \root\default does NOT work!
Dim scope As New ManagementScope("\\.\root\cimv2")
' Clear out the ListView we're using to show the drives and serial numbers.
ListView1.Items.Clear()
Dim query As New ObjectQuery("SELECT * FROM Win32_PhysicalMedia")
Dim searcher As New ManagementObjectSearcher(scope, query)
Dim objectCollection As ManagementObjectCollection = searcher.Get()
For Each obj As ManagementObject In objectCollection
' The ListView is assumed to have two columns setup to old these.
Dim newItem As New ListViewItem(New String() {CStr(obj("Tag")), CStr(obj("SerialNumber")).Trim})
ListView1.Items.Add(newItem)
Next
' It's very important to dispose these objects when your done with them! If
' you don't, you'll end up with a handle leak and eventually crash the system.
objectCollection.Dispose()
searcher.Dispose()
End Sub
Now, like I said before, not every device fills in the information you want. In one of my test systems, only 2 out of 6 hard drives returned serial numbers, and one of those needed to be Trim 'd to remove some leading spaces.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Do we need to change the scope from machine to machine?
When i tried your code am getting Error Msg as "Object reference not set to an instance of an object."
|
|
|
|
|
Thoombath wrote: Do we need to change the scope from machine to machine?
Yes. If you want to connect to a different machine you have to change the \\.\root\cimv2 to \\machineName\root\cimv2 .
Thoombath wrote: When i tried your code am getting Error Msg as "Object reference not set to an instance of an object."
It would help to know on which line this is occuring.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I changed to my Computer Name still that Error is coming.
Its occuring on :
Dim newItem As New ListViewItem(New String() {CStr(obj("Tag")), CStr(obj("SerialNumber")).Trim})
|
|
|
|
|
Then no SerialNumber object was returned, or that object isn't in the collection. Calling Trim on it fails because you can't do this:
Nothing.Trim
Wrap that line and the next one in a Try/Catch block to ignore any errors:
For Each obj As ManagementObject In objectCollection
' The ListView is assumed to have two columns setup to old these.
Try
Dim newItem As New ListViewItem(New String() {CStr(obj("Tag")), CStr(obj("SerialNumber")).Trim})
ListView1.Items.Add(newItem)
Catch
' Warning! This will ignore ANY AND ALL ERRORS with the above two lines of code!
' In a production environment, this is usually NOT a good idea!
End Try
Next
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Now the Error is gone. But nothing is populated on the List View.
This might be coz of my hard drives. Is this requires Administrative login or role to function this Method?
Thanks
|
|
|
|
|
The code has to have FullTrust in order to run. That means, by default, it needs to be run from the local workstation, or if querying other machines, needs to have admin rights to the target workstation.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I am trying this in an Windows Based Application and am quering to the local machine. Am a user under a Domine. Will this be the reason for not getting the answer?
|
|
|
|
|
So long as that account has admin rights to the machine, it should work. The other possibility is that the data isn't being created by any providers installed on the machine. People keep asking "How do I get the serial number of my motherboard using WMI??". Well, if the manufacturer of the motherboard doesn't provide a WMI provider, you can't. On top of that, there's nothing that says the manufacturer, even though they are providing a WMI Provider, has to fill in these kinds of details.
Like I said in my previous post, I ran the code on one of my test machines (with 6 hard drives in it) and only 2 returned serial numbers!
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Anyways thanks Dave.
I will try it with other systems and see how it goes.
Regards,
Anas TM
|
|
|
|
|
I am looking for retrieving the Serial Number and Hard Disc detail of an Windows Xp Machine using Vb.Net. I found some code using query to Win32_PhysicalMedia, but its not working properly. Can any one help me in this...
Regards
Anas
|
|
|
|
|
Let's see the code you're using. WMI is about the only method you've got to get this information. But, there's nothing that says the hardware or the provider for it has to fill in all the details of what you're looking for, like the serial number.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Hi Dave,
I have posted the code for getting Serial Number using the WMI
The post subject is SerialNumber of an Xp Machine.
Thanks,
Anas
|
|
|
|
|
Sorry if this is a silly question and I may just be being thick, but I can't seem to get a startup project going as I don't want to use a one-click setup, in the MS instructions it says, you go file ==> add ==> New Project, and select startup project from there, I just don't have this option at all, I'm using VB.net 2005 express edition.
many thanks..
|
|
|
|
|
I think you're referring to the Setup project, not Startup.
And no, the Express Editions don't come with one. They're relegated to ClickOnce deployment.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
yup, setup project and b****r I had an idea that might be the case...
|
|
|
|
|
|
The Express Editions don't come with the Setup projects you use in your article. Express only uses ClickOnce Deployment.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|