|
Hello Dave,
Thanks for the link .Can you help me for a start ???
Regards
Rizwan
|
|
|
|
|
I already did with the links. I've never written an Excel AddIn, nor have I touched VB6 in about 8 years.
|
|
|
|
|
Thanks for it Dave.
Regards
Rizwan
|
|
|
|
|
Hi All
I Want To Sort The DataGridView by Design And Code
pls Send Me a Code As Sample
Thanks
Thaer
|
|
|
|
|
In what way is the build-in DataGridView sort function not adequate?
|
|
|
|
|
See here.
My signature "sucks" today
|
|
|
|
|
Why can't you find out for yourself?
Look on Google.
Read a book.
I assume that you are in the IT development business or wish to be.
If that IS the case you won't get very far if you ask everyone else to do your work for you.
India I assume?
|
|
|
|
|
I have a total of 65 text boxes which the user can fill in. They are 13 down and 5 across. Each row is related to a particular material (which can change daily -see earlier posts) the columns are for quality of material.
In Debug mode stepping through the code this is what happens:
If I pull up the form and enter data into one textbox and then click on the save button the program goes through the save routine, but there is nothing to save and then it hits the Lost_focus event of the text box and runs through and saves the data to the collection class but doesn't save the information.
If I enter one text box and then tab to another the Lost_focus of the first textbox saves the data to the collection class and then click on the Save button the program saves the info to the tables properly and then runs the Lost_focus event of the second text box.
I don't remember this happening in VB6 so I am sure it has to do with the new form collection class, etc. I am confused and wonder now what is the proper way to proceed. I need to be able to save for each form anywhere from 1 to 65 types of material on each form.
The text_changed proeprty won't work as it fires on each digit being entered- 123 causes the event to fire 3 times.
Here is the code for the SaveMaterial function from the save button, the StoreMaterial2COL function and the first couple of lost_focus Subs:
Private Function SaveMaterial() As Boolean
Try
' The index of a zero-based collection is Count property minus 1.
Dim iCnt As Integer
iCnt = myMaterialsCollection.Count
iCnt = iCnt - 1
With myMaterialsCollection
For Each aItem In myMaterialsCollection
If iCnt = -1 Then
Exit For
End If
_gblString = CreateGUIDString()
gblConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\JWI\Data\JWI.mdb;Jet OLEDB:Database Password=jWi;")
strData = "INSERT INTO LOLItems (LOLItemsID, LOLIFormID, Type, TextBox, MaterialsID, Units, DateCreated )" _
& " VALUES ('" & _gblString & "', " _
& "'" & _frmGuid & "', '" _
& 1 & "',' " _
& aItem.txtBoxName & "',' " _
& aItem.MaterialID & "',' " _
& aItem.jnts & "',' " _
& Now() & "');"
gblCMD.Connection = gblConn
gblCMD.CommandText = strData
Dim cmd As New System.Data.SqlClient.SqlCommand
gblConn.Open()
gblCMD.ExecuteNonQuery()
myMaterialsCollection.Remove(iCnt)
iCnt = iCnt - 1 'decrement until empty
Next
End With
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Function
Public Function StoreMaterial2COL(ByRef matID As String, ByRef ctrlname As String, ByRef jnts As String)
Try
'need to check to make sure the txtboxName has not been entered already
'if so then the user is updated the amt and we need to update the
'jnts and not add a new record.
aItem.txtBoxName = ctrlname
aItem.MaterialID = matID
aItem.jnts = jnts
myMaterialsCollection.Add(aItem)
Catch ex As Exception
'Catch ex As System.InvalidCastException
MsgBox(ex.ToString)
End Try
Return True
End Function
'*#*#*#*#*#*#*#*#*#*#*#*#*
'Need to try to make a more generic method of doing this- a control array maybe????
'This is for column 1 Junk Rods
Private Sub txtRodJ_0_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtRodJ_0.LostFocus
StoreMaterial2COL(lblRods_0.Tag, txtRodJ_0.Name, txtRodJ_0.Text)
End Sub
Private Sub txtRodJ_1_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRodJ_1.LostFocus
StoreMaterial2COL(lblRods_1.Tag, txtRodJ_1.Name, txtRodJ_1.Text)
End Sub
Private Sub lblRodJ_2_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRodJ_2.LostFocus
StoreMaterial2COL(lblRods_2.Tag, txtRodJ_2.Name, txtRodJ_2.Text)
End Sub
Private Sub txtRodJ_3_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRodJ_3.LostFocus
StoreMaterial2COL(lblRods_3.Tag, txtRodJ_3.Name, txtRodJ_3.Text)
End Sub
As always any assistance is greatly welcomed.
Larry
|
|
|
|
|
Have you tried using the control's Validating or Validated events?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Not sure about those events but will look into them. Thanks Lary
|
|
|
|
|
I find it's not a good idea to bug the user with a save every time a control looses focus. In fact, editing of the user's inputs in all controls should not happen until a save is triggered. In my opinion, a save should happen when one of two events happens ... (1) a Save button is clicked by the user (hence they expect it to happen), or (2) the FormClosing event fires. And the latter should trigger a save only if the user made at least one change in any of the controls which should cause a message box to display to ask the user if the changes are to be saved or not. In other words, the user should be alerted that they are about to loose changes; but, should have the option to discard or save the changes.
Hope all that makes sense. There's an article on this topic that you may find interesting. Click here to read it.
|
|
|
|
|
The Save works only when they click on the Save button to cycle through the Material Collection class. When the control loses focus then it STORES the necessary info into the Material collection class. I figured this would be easier than cycling through each text box when the Save button was clicked and then doing something like :
if len(textbox.text)> 0 then
Store necessary info to table
end if
and then to the next textbox and so on.
My problems seems to be that the events don't fire in the sequence that I'm expecting. I can enter data into 2 or 15 text boxes and when I click on Save it always seems to handle the number of items in the collection and THEN go to at least one more textbox even though there is no data stored in it. If I enter data into just one text box then the Save routine runs before the STORE routine for the textbox and then that store routine runs and then the next textbox lost focus runs also. Not sure why?
Thanks,
Larry
|
|
|
|
|
I'm not following for some reason. That sounds awfully convoluted. Guess I'd have to look at the code.
|
|
|
|
|
Your right it is convoluted. Let me lay out part of the design specs. We are dealing with scrap material commodity selling. There will be 30-40 buyers/sellers working with the form and can make 20-30 buys/sells per hour. What makes it difficult is they want to top selling items from yesterday to show as the first item on the form today. In other words, if 3/8 inch rod traded more yesterday then today it needs to be at the top of the list. If today 5/8 inch rods sold the most then tomorow they need to be at the top of the list. So each day, the order in which the items show can change.
I can calculate total number of sales of each item and then fill the items into a label which has the name of the item and then in the labels .tag property I store the GUID for the item. Then I name each of the textboxes acrosss the screen based upon the item name.
Each item has 5 grades from Junk to New and it is possible that on one order the user can sell 20 joints of 3/8 inch rod Junk, 15 joints of 3/8 inch rod Good (B2) and 10 rods of 3/8 inch rod New.
That is why I thought the best reason is to store each entry into a text box on the Lost_focus event into a Material collection class and then save the items to the tables from that class when they click on the Save button which will also close the form and allow them to go on to the next order.
Anything anyone can come up with to make it easier will be greatly appreciated.
Larry
|
|
|
|
|
I'm not seeing the need to store the data in both a collection and in the textboxes. Why can't the data reside just in the text boxes until the Save button is clicked? Then there would be no background overhead trying to duplicate the data from the textboxes in a collection class. It sounds to me like the simpler, and possibly more robust approach would be to remove the LostFocus events entirely. When the Save button is clicked, instantiate the collection, transfer the data from the textboxes to the collection, and then store the data in the database.
|
|
|
|
|
Right, but I initially thought that I would have to cycle through EVERY textbox and if there was a value in it then store the data directly to the table then. I would be able to pick up the MaterialID from the GUID stored in the label for the row. I just thought that would be more time consuming and convoluted than this way.
But I am open for suggestions. There are a lot more textboxes on the form than just the 65 for the materials so I have to be able to prevent any others from being searched. I beleive that can be done by cycling through the textboxes on tabLOLfrm.TabPage1 and tabLOLfrm.TabPage2 and tabLOLfrm.TabPage3. I beleive that the textboxes on the container are not recognized by the form so that might be one way. I remember that VB6 had the control array feature which was much easier to utilize. I have seen a number of attempts to create a control array in VB.Net but don't know exactly how to make a simple easy way to work. I've tried about 3 diferent ways from several different sources.
Again, I appreciate your input and insight so far, any further assistance is greatly apreciated. I'm going to start working and this suggestion tonight and see what I can accomplish.
Larry
|
|
|
|
|
From your description of your form it seems to me that you might be better served by designing a user control that contains the 5 text boxes, laid out as you need them, together with any labels, if any.
Then you only need to add 13 of these user controls to something like a scroll box on your form. If nothing else it would make your code much less complex and therefore easier to read/maintain.
Fortunately those nice folks at M$ must have been thinking of you and your problem they have released Microsoft Visual Basic Power Packs 3.0[^] which contains a new control, for VB.NET anyway (I believe a similar control was available for VB 6), called the DataRepeater . The download from the above link contains full source code and Help files with some samples.
For a quick 'HowTo' take a look at DataRepeater Control For Windows Forms[^].
I have just noticed from that link that if you have installed VS2008 SP1, you should already have this control.
If you have the time, I really recommend that you, at least, take a look at the 'HowTo' as I really believe that it will help with your current project.
Good luck anyway.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
Dim f1 As New Font("Arial", 8.25)
Dim f2 As New Font("Arial", 8.25, FontStyle.Bold)
' f1 is ok with option strict on or off
' f2 is ok with strict on, but with off I get an overload resolution failure
The complete diagnostic is:
Overload resolution failed because no accessible 'New' can be called without
a narrowing conversion:
Public Sub New(familyName As String, emSize As Single, unit As
System.Drawing.GraphicsUnit)
: Argument matching parameter 'emSize' narrows from 'Double' to 'Single'.
Public Sub New(familyName As String, emSize As Single, unit As
System.Drawing.GraphicsUnit)
: Argument matching parameter 'unit' narrows from 'System.Drawing.FontStyle'
to 'System.Drawing.GraphicsUnit'.
Public Sub New(familyName As String, emSize As Single, style As
System.Drawing.FontStyle)
: Argument matching parameter 'emSize' narrows from 'Double' to 'Single'.
Option Strict is 'off'
Option Explicit is 'on'
Treat all warnings as errors is 'on'
If you can think then I Can.
|
|
|
|
|
Have you tried declaring your fonts with the full declaration i.e System.Drawing.Font . I have had this problem before and it was a conflict with another class that had a Font property (I tink it might have been the Excel Interops IIRC). Then try also declaring FontStyle.Bold as System.Drawing.FontStyle.Bold , just to avoid any Namespace conflicts.
Happy Coding
|
|
|
|
|
Yes i try this but nothing happen.
If you can think then I Can.
|
|
|
|
|
The error is encountered because the constructor cannot convert double to float implicitly. You need to add "F" to your font sizes in order for the constructor to determine that it is a float.
Dim f1 As New Font("Arial", 8.25F)
Dim f2 As New Font("Arial", 8.25F, FontStyle.Bold)
|
|
|
|
|
I had mistake to define my SQL Server database table with all columns with TEXT, with my DataGridView the following codes are working fine (it will show every thing with its randome order):
cmd = New SqlCommand("SELECT * FROM GuestInfoStore", con)
If con.State = ConnectionState.Closed Then con.Open()
myDA = New SqlDataAdapter(cmd)
myDataSet = New DataSet()
myDA.Fill(myDataSet, "MyTable")
DataGridView_INFO.DataSource = myDataSet.Tables("MyTable").DefaultView
In my table, there is a column FirstName, if I use:
cmd = New SqlCommand("SELECT * FROM GuestInfoStore ORDER BY FirstName", con)
I will have an error since SQL can't compare with Text column, but it is too late for me to change FirstName column back to char(50) or so ... can anyone help me on this?
Thank in-advanced
|
|
|
|
|
Curious 2009 wrote: it is too late for me to change FirstName column back to char(50)
it is never too late to fix a mistake. Things can only get worse if you don't.
You could:
- add a field with the correct type;
- automatically copy the existing field to the new one;
- gradually adapt your software, first the field producers (methods that write the field): make them write both fields; then the field consumers (the methods that read the field): make them read the new field.
- when all is done, remove the redundant field.
The alternative is a lot of ugly code, that will grow and grow over time, as you keep adding features.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
You are right & I will do as you suggested!
Thank
|
|
|
|
|
Good.
If it is a simple TEXT->VARCHAR change, I think you can tell SQL Server to do that in place, in a single step. I haven't so far, I have done similar things with MySQL.
It is trickier when more complex formatting is involved, such as string->DateTime. It is always safe to make an extra field as a backup!
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|