|
|
Hi,
I'm trying to display a recordset that is created by using
"SELECT column1, column2 FROM [Table1] WHERE ID = '1'".
How can I display it into a listview?
Thank you very much
|
|
|
|
|
recordset.MoveFirst
Do while not recordset.EOF
if not recordset("field").value = nothing then
listbox.items.add(recordset("field").value)
end if
recordset.MoveNext
Loop
|
|
|
|
|
|
Hello!
My aim is to move the label inside a panel while the mouse is down on the label. How can I locked the cursor while the cursor is on the label and then move the label inside the panel with mouse?
Thanks!
Bedri
|
|
|
|
|
Well, there's nothing that does this for you, so you have to implement it yourself. Basically, you have to handle the MouseDown, MouseUp, and MouseMove events of the Label control you want to be moveable. You'll need a couple of Form class scoped variables, the first being an offset value that you store when the mouse is clicked on the label, the second is just a boolean flag that says the mouse button is held down and we're moving the label.
Public Class Form1
Private cursorOffset As Point
Private moving As Boolean
Private Sub Label1_MouseDown(blah, blah) Handles Label1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
cursorOffset = e.Location
moving = True
Cursor = Cursors.SizeAll
End If
End Sub
Private Sub Label1_MouseUp(blah, blah) Handles Label1.MouseUp
moving = False
Cursor = Cursors.Default
End Sub
Private Sub Label1_MouseMove(blah, blah) Handles Label1.MouseMove
If moving then
Dim clientPosition = Me.PointToClient(Cursor.Position)
Label1.Location = New Point(clientPosition.X - cursorOffset.X, clientPosition.Y - cursorOffset.Y)
End If
End Sub
End Class
You'd probably be better off modifying this code and moving it to your own implementation of a movable Label control.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi,
in .Net i have used 'Generate Managed Class' to generate win32_printer.vb
how can i use this class to get all all the printer names on my computer?
thanks
|
|
|
|
|
Just so we're clear about what you're talking about... How did you do this "Generate Managed Class" thing? What was the tool you used and the command line you used to launch it?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
This is how i got there:
Install the WMI Extensions
Open Visual Studio
New Project
Go to Server Explorer / Management Classes
Right Click -> Add Class
Drill down to root\CIMV2 : Printers
Click Add and OK
Right click on the new node -> Generate Managed Class
-- modified at 21:39 Friday 27th January, 2006
|
|
|
|
|
First, toss the "Generated" garbage in the trash. Do it by hand so you can understand what's going on and have greater control over it. It also makes asking and answering questions a whole lot easier.
Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_Printer")
Dim prn As ManagementObject
For Each prn In searcher.Get()
Console.WriteLine("Printer Name = " & prn("Name").ToString())
Next share
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Ummm.... The link you posted doesn't have anything to do with returning all the printer names on the machine.....??
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Need help from a crystal reports Guru.
I am trying to display values from the text boxes on this one form. The crystal report is already connected to the database and all the fields are there. When I try to run the report it pulls all the data from the DB. Below is the code. Please help!
Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Load<br />
Dim myDS As New Dataset1<br />
Dim rptdata As New dbAccess<br />
Dim rptval As New Change<br />
<br />
Dim rpt As New Chgmgt<br />
rpt.SetDataSource(myDS)<br />
CrystalReportViewer1.ReportSource = rpt<br />
<br />
Dim LogNumber1 As Integer<br />
Dim Daterequested1 As String<br />
Dim TargetDate1 As String<br />
Dim Time1 As String<br />
Dim RequestedBy1 As String<br />
Dim ProjectName1 As String<br />
Dim ChangeDescription1 As String<br />
Dim Users1 As String<br />
Dim Department1 As String<br />
<br />
LogNumber1 = rptval.LogNumber<br />
Daterequested1 = rptval.DateRequested<br />
TargetDate1 = rptval.TargetDate<br />
Time1 = rptval.Time<br />
RequestedBy1 = rptval.RequestedBy<br />
ProjectName1 = rptval.ProjectName<br />
ChangeDescription1 = rptval.ChangeDescription<br />
Users1 = rptval.Users<br />
Department1 = rptval.Department<br />
<br />
<br />
End Sub
------------------------------------------------------------------------
|
|
|
|
|
Hi everyone
Is it possible to use 1 database, to be accessed through a VB web form as well as through a VB windows application ? If so, can someone give me some direction on this ?
Derek
|
|
|
|
|
Sure. All you need to do is keep all your database code in a data layer class. You can then reuse that code in any UI application you want. You're looking for information on 3-tier design.
You can find a pretty good example here[^].
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Hi, I'm new to VB.NET. I use a datalist to display and edit my records form Access database.
I got problems whenever I try to update or delete a record, it gives me "The ConnectionString property has not been initialized" error. Does anybody has any idea how to solve this problem? Where should I change the code? Please show me how to do it. Thanks.
Here's the code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
LoadData()
End If
End Sub
Public Sub LoadData()
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("CampusVoting.mdb")
myconnection = New OleDbConnection(strconn)
cmdReq.CommandText = "select * from News"
cmdReq.Connection = myconnection
cmdReq.Connection.Open()
dr = cmdReq.ExecuteReader
NewsList.DataSource = dr
NewsList.DataBind()
cmdReq.Connection.Close()
End Sub
Sub Del_Command(ByVal sender As Object, ByVal e As DataListCommandEventArgs)
Dim title As String
title = NewsList.DataKeys(e.Item.ItemIndex)
Dim cm As New OleDbCommand("delete from News where NewsID = " & title & "", myconnection)
cm.Connection.Open()
cm.ExecuteNonQuery()
cm.Connection.Close()
LoadData()
End Sub
Sub Cancel_Command(ByVal sender As Object, _
ByVal e As DataListCommandEventArgs)
NewsList.EditItemIndex = -1
LoadData()
End Sub
Sub Edit_Command(ByVal sender As Object, _
ByVal e As DataListCommandEventArgs)
NewsList.EditItemIndex = e.Item.ItemIndex
LoadData()
End Sub
Sub Update_Command(ByVal sender As Object, _
ByVal e As DataListCommandEventArgs)
Dim tbox As TextBox
Dim Title_id As String
Dim Title, Descr As TextBox
title_id = NewsList.DataKeys(e.Item.ItemIndex)
Title = e.Item.FindControl("NewsTitle")
Descr = e.Item.FindControl("NewsDesr")
Dim cmd As New OleDbCommand("Update News set NewsTitle = '" & Title.Text & "', NewsDesr='" & Descr.Text & "' where NewsID=" & Title_id & "", myconnection)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
NewsList.EditItemIndex = -1
LoadData()
End Sub
|
|
|
|
|
The error is pretty obvious. You're first problem is that your using class scoped (or global if you must use the term) variables for hold your database objects. This is really bad practice.
I would suggest moving your database code to a data layer class. This removes your UI from handling the database stuff itself and encapsulates the data so you can easily reuse it from a Windows Forms app, if you so choose.
The problem is pretty obvious if you follow your code. An ASP.NET app is only alive for the time it takes to generate a single HTML page. Once the page is sent to the client, your app effectively quits. When the use clicks on a button on the HTML page, a request is sent back to your IIS server and another instance of your app is launched. It knows nothing of the previous instances "global" variables that you setup.
Knowing this, follow your code. The only time you ever initialize the strConn or myConnection variables is on the first page that is sent to the client. After that, you never initialize them again when the user clicks on the various control on your page. Remember that "IsPostBack" statement?
Basically, there is no "change this line to this" that's going to fix your code. It needs a major rewrite to get this datbase code to work...
Public Class DataLayer
Public Shared Function GetDatabaseConnection() As OleDbConnection
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("CampusVoting.mdb"))
Return conn
End Function
.
.
.
End Class
Get the idea?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 10:33 Friday 27th January, 2006
|
|
|
|
|
Hi,
Thanks for the reply, now I got the idea how to avoid that error again.
|
|
|
|
|
I am trying to disable a tab page. In this example, I have a tab control with 3 tab pages. What I want to do is if I select say Tab Page 2, then this is disabled and will not let me view the contents.
Here is my code
Private Sub TabControl1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.Click
If TabControl1.SelectedIndex = 1 Then
TabPage2.Enabled = False
End If
End Sub
I have also tried TabPage2.visible = false
Nothing seems to happen when I try the above. What am I doing wrong?
|
|
|
|
|
The TabPage cannot be Disabled. You actually have to remove it from the TabControl's TabPages collection and add it back when you need to show it.
In practice, this is not a good UI design. Tab's put back into the collection will appear at the end of the tab control, effectively rearranging the tabs. There is no way to sort them without removing ALL the TabPage controls and re-adding them in the order that you want them to appear.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote: There is no way to sort them without removing ALL the TabPage controls and re-adding them in the order that you want them to appear.
I also used to have a problem with the above problem like the person that post the previous thread. If we could not hide or disable, how about the visitble property? What is the meaning of visible property for each tab page if it still could not hide the page that we want to hide?
On the other hand, if we remove the any page, how about the control on that tab page? Do we need to add it again or not?
|
|
|
|
|
TabPage inherits from Control. Control is what is supplying the Enabled and Visible properties. But, in TabPage, they're not wired up to do anything, so they don't work.
When you remove the TabPage from the TabPages collection, you're just removing an object from a collection. If you don't save that object in another variable or collection somewhere first, it's reference count will drop to 0 and it, and all the controls on it, will be destroyed.
If you save the TabPage somewhere else, then nothing will happen to the controls on that page. They'll still be alive and well, so long as their parent TabPage object is still alive. All you have to do is re-add the TabPage back to the TabPages collection of any TabControl object.
You could even move an entire TabPage, controls and all, from one TabControl to another.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote: If you don't save that object in another variable or collection somewhere first, it's reference count will drop to 0 and it, and all the controls on it, will be destroyed.
How to save a TabPage collection?
Dave Kreskowiak wrote: You could even move an entire TabPage, controls and all, from one TabControl to another.
How to move an entire TabPage and its control from one TabControl to another?
|
|
|
|
|
Dim savedTabPage As TabPage = TabControl.TabPages(3)
NewTabControl.TabPages.Add(savedTabPage)
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|