|
Well, I suggest you use the link provided by MicroVirus to learn the basics of the ListView . Then you should be able to work it out yourself.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
What you do is you add a ListViewItem via ListView.Items.Add, and store the returned ListViewItem object. Then, you can use this object to add subitems via ListViewItem.SubItems.Add.
See, for instance, MSDN ListView sample[^]
|
|
|
|
|
Maybe it's better to use ms flexgrid.but i don't know how to save flexgrid in my ms acess database.
|
|
|
|
|
Hi,
I have a public function that generates a CRC32 checksum of a file. What I am looking to add to it is a progress bar that progresses as the checksum is created.
CRC32 Function
Public Function GetCrc32(ByRef stream As System.IO.Stream) As Integer
Dim crc32Result As Integer
crc32Result = &HFFFFFFFF
Dim buffer(BUFFER_SIZE) As Byte
Dim readSize As Integer = BUFFER_SIZE
Dim count As Integer = stream.Read(buffer, 0, readSize)
Dim i As Integer
Dim iLookup As Integer
Dim tot As Integer = 0
Do While (count > 0)
For i = 0 To count - 1
iLookup = (crc32Result And &HFF) Xor buffer(i)
crc32Result = ((crc32Result And &HFFFFFF00) \ &H100) And &HFFFFFF
crc32Result = crc32Result Xor crc32Table(iLookup)
Next i
count = stream.Read(buffer, 0, readSize)
Loop
GetCrc32 = Not (crc32Result)
End Function
the function is then called when I click on a button
Dim f As FileStream = New FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
crc = c32.GetCrc32(f)
lblCRC32.Text = Hex(crc)
How do I add a progress bar to work with the function and display the actual progress.
Thanks
J
|
|
|
|
|
What you do is you get the file length (stream.Length ) and then you divide the current amount of bytes processed by this value. If you multiply this fraction by 100 then you get the percent complete.
All you have to do then is add a progress bar to your form, set its Min to 0, Max to 100, at the start of GetCrc32 set its Value to 0 and then after every iteration you set the progressbar Value to the percent you calculated.
On a final note: you might want to do this calculating and updating the progress bar only every N iterations rather than each to avoid slowing down the function, where N is some reasonable value, like 512 or 1024 (after half and 1 KiB reads respectively).
|
|
|
|
|
Thank you for your answer but how do I know how many bytes are processed
|
|
|
|
|
Edit: sorry ignore last response, didn't read the question properly......
Anyway, You know the file length from the Stream.length as per the previous message.
You also know how my bytes are being read on each iteration on the buffer.
You add a totaliser, and with each byte read create the total read so far, then its simply: (total read so far / total length) * 100
|
|
|
|
|
DaveAuld is correct. Also, the stream.Position gives how many bytes you've read in this case.
|
|
|
|
|
Cool. Thanks guys for the help
|
|
|
|
|
I have a MDB that has 600000 records(more or less). When I'm getting data from that MDB it takes time to display the result in List, how can I make my program faster.
|
|
|
|
|
You need to either filter the results so that the user starts getting only the results that they are interested in (let's face it, no-one wants to scroll through 600000 results to find the ones they want), or you need to institute some sort of paging, i.e retrieve only a few results at a time and give the user buttons or links to go forward or backward. Unfortunately, I can only be vague in my answer as you are vague in your question. If you give us more information, perhaps we can give you more specific help.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Actually before I display any record user must input a filter. My problem is when I Open a ResultSet its takes 10 or more seconds to display to List. Is there a way to make the query fast.
|
|
|
|
|
It still seems like the resultset is too large, that is what is taking the time. In that case, you would need to set up paging and only return a few results at a time, and give the user options to move forward and back - similar to what happens here on the forums. You generally only see the first 25 / 50 posts on the page at a time and if you want to view any other posts from before you need to go to a different page.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
I's sorry but the resultset is not large, actually it returns just one record.
|
|
|
|
|
That then would point to either
1. Indexing on the database
2. Your query for getting the single result
3. Code used to execute query.
They are in the order that I would check
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
have your database properly indexed.
warning: more (and more complex) indexing gives faster look-ups and slower inserts.
|
|
|
|
|
"MDB" is a Microsoft Database, could be either Access or Sql Server. Any large list will take time to go from A (the database) to B (the memory of your app).
As another alternative, have a look at the VirtualMode[^] of the DataGridView . Works fastest using the DataGrid , if you don't mind the ugly interface (loads faster than loading a table in Sql Management Studio)
Bastard Programmer from Hell
|
|
|
|
|
hi everyone,
I always got an error Restore failed for Server '...\SQLEXPRESS'
I googled it already and bunch of result.
but still, i can't solve it.
Details:
*windows xp
*sql server 2005 using PCNAME\SQLEXPRESS, (windows authentication mode)
*visual studio 2005
*filePath= C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\DBNAME.bak
note: sometimes it goes successfully but sometimes got an error.
please help! thanks in advance.
here's the code
Using cnn As New SqlConnection(constrSQL)
cnn.Open()
dbName = cnn.Database.ToString()
cnn.ChangeDatabase("master")
Dim sc As New ServerConnection(cnn)
Dim sv As New Server(sc)
filePath = Path.Combine(filePath, databaseName & ".bak")
Dim bdi As New BackupDeviceItem(filePath, DeviceType.File)
Dim resDB As New Restore()
resDB.Database = dbName
resDB.Action = RestoreActionType.Database
resDB.ReplaceDatabase = True
resDB.NoRecovery = False
resDB.Devices.Add(bdi)
resDB.PercentCompleteNotification = 10
AddHandler resDB.PercentComplete, AddressOf ProgressEventHandler
resDB.Database = dbName
Try
resDB.SqlRestore(sv)
sv.Refresh()
sv = Nothing
Catch ex As Exception
log.Debug(ex.ToString)
Throw (ex)
End Try
End Using
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
There may be active uses on the db when you are trying to restore a backup..
|
|
|
|
|
thanks prdshukla
i think no other users who use the db because its a local machine and only 1 user, and in the end
of my code I set to nothing the server.
resDB.SqlRestore(sv)
sv.Refresh()
sv = Nothing
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
Hi,
The post above is correct.
C#Coudou wrote: note: sometimes it goes successfully but sometimes got an error.
Next time, include the message of the error. It can be quite helpful.
Bastard Programmer from Hell
|
|
|
|
|
thanks Eddy Vluggen
Eddy Vluggen wrote: Next time, include the message of the error. It can be quite helpful.
the subject itself of this post is error message of my program.
but you gave me an idea what is the real error which is the inner exception, and i found out that some process are not close or dispose. so i added a kill process, and it goes smoothly and perfectly.
thanks you very much.
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
Hi
I am trying to place a red rectangle around a control on a form using the PowerPacks RectangleShape.
I managed to do that if the control is on the form, but if the control is in container (groupbox, panel) i am getting wrong measurements.
Here is my code
Sub PutRedRectangle(ByVal _ctrl As Control)
Dim canvas As New Microsoft.VisualBasic.PowerPacks.ShapeContainer
Dim rect1 As New Microsoft.VisualBasic.PowerPacks.RectangleShape
canvas.Parent = Me.GroupBox1
rect1.Parent = canvas
rect1.Left = _ctrl.Left -1
rect1.Top = _ctrl.Top - 1
rect1.Width = _ctrl.Width + 2
rect1.Height = _ctrl.Height + 2
rect1.BorderWidth = 2
rect1.BorderColor = Color.Red
End sub
If I placed a textbox on a form, the code will work
If I placed a textbox in groupbox on a form, the rectangle will not be placed correctly around the textbox.
Is there special calculations or formula I should follow?
[EDIT]
Any other way of placing a red rectangle around a control is welcomed.
modified on Wednesday, September 7, 2011 6:32 AM
|
|
|
|
|
Are you sure that the textbox control is actually *in* the groupbox? When debugging, check _ctrl.Parent to see if it refers to the groupbox.
Also, PutRedRectangle can only be called once, as MSDN for the ShapeContainer specifically states that each container control can only have one ShapeContainer in it. If you call it multiple times, you are going to have to check for the existence of a ShapeContainer inside the container control (_ctrl.Parent control is the container) and use that when found, or create a new one when not found.
|
|
|
|
|
MicroVirus wrote: Are you sure that the textbox control is actually *in* the groupbox? When debugging, check _ctrl.Parent to see if it refers to the groupbox.
Yes, I checked, it is inside it.
MicroVirus wrote: Also, PutRedRectangle can only be called once
Thank you for this info, but my function create new Shape and new rectangle each time I call it (which is what I want for now) my next step (after fixing my current) is to remove the rectangle.
Well, you made me consider the .parent for the control I am sending and that help me to create a customized function if the .parent type is GroupBox
Sub PutRedRectangle(ByVal _ctrl As Control)
Dim canvas As New Microsoft.VisualBasic.PowerPacks.ShapeContainer
Dim rect1 As New Microsoft.VisualBasic.PowerPacks.RectangleShape
Dim _parent As Control = _ctrl.Parent
rect1.Parent = canvas
canvas.Parent = _parent
canvas.Name = "canvas_" + _ctrl.name
rect1.Width = _ctrl.Width + 2
rect1.Height = _ctrl.Height + 2
rect1.BorderWidth = 2
If TypeOf(_parent) is GroupBox
rect1.Left = _ctrl.Left - 1 - _parent.Padding.Left
rect1.Top = _ctrl.Top - 17 + (_parent.Margin.Top - _parent.Padding.Top)
rect1.BorderColor = Color.Red
Else
rect1.BorderColor = Color.Blue
rect1.Left = _ctrl.Left - 1 - _parent.Padding.Left
rect1.Top = _ctrl.Top - 1 - _parent.Padding.Top
End If
canvas.SendToBack
End Sub
Sub RemoveRedRectangle(ByVal _ctrl As Control)
Dim q = From c As Control In _ctrl.Parent.Controls Where c.Name.StartsWith("canvas_" + _ctrl.Name) Select c
q.First.Dispose
Me.Refresh
End Sub
It seem the groupbox has invisible header which should be calculated depends on the font size when assigning the .Top for the rectangle. ( I don't know how to get it)
Also, the Rect1.Top is affected with margin and padding if inside a groupbox, and it is not affected if inside a panel.
So, the above code works correctly so far.
Also the remove is working fine but I had to refresh the form
If any one has a suggestion or another idea, I will be thankful.
Thanks for your help
|
|
|
|