0

ahaaaaaa!

I reput the end if back in at the end, just above the end sub LOL


remembered I was trying something and took it out

okay no errors now, gonna cross my fingers and give this a whirl :)

0

ahaaaaaaaaa!
that allowed me to save it, didnt give me any errors :)

Now...LOL....
what do I need to do, I was able to save it and it did open excel when I clicked on it to open after saving. But the excel sheet was empty.

Do I need to go into excel and set up fields based on my Grid?

boy o boy I cannot thank you enough! The amount of patience and help you have given this and me is just astronomical! Thank you a thousand times over! :)

0

well pooop...no, that didnt work.
I went in and named columns according to the grid column names and when I save the grid it lets me...but then I go into folders and open the saved sheet and there is nothing there?

0

good morning :)

nope, I fill in at least one line in the gridview..but maybe I should try filling in several lines?

0

I dunno Oxiegen,
I tried filling in several lines of the grid, and I even went and put the extensions into the savefileDialog (lol which by the way I still have) and filled in about 20 lines of the grid..and still the same thing.

It will allow me to save but it is still saving a empty file?

0

That's wierd.
If you debug the For Each..Next code, what does row contain?
And what does row.Cells(0) contain?
Also, is the string variable line being filled?
Have you also perhaps tried to add row.Cells(0).Value.ToString()?

0

I dont know what you mean LOL..but this is all there is so far:

this is the code written :

Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Dim fileName As String = ""
        Dim dlgSave As New SaveFileDialog
        dlgSave.Filter = "Text files (*.txt)|*.txt|CSV Files (*.csv)|*.csv"
        dlgSave.AddExtension = True
        dlgSave.DefaultExt = "txt"
        If dlgSave.ShowDialog = Windows.Forms.DialogResult.OK Then
            fileName = dlgSave.FileName
            SaveToFile(fileName)
        End If
    End Sub
    Private Sub SaveToFile(ByVal fileName As String)
        If DataGridView1.RowCount > 0 AndAlso DataGridView1.Rows(0).Cells(0) IsNot Nothing Then
            Dim stream As New System.IO.FileStream(fileName, IO.FileMode.Append, IO.FileAccess.Write)
            Dim sw As New System.IO.StreamWriter(stream)
            For Each row As DataGridViewRow In DataGridView1.Rows
                Dim line As String
                line = row.Cells(0).ToString()
                line &= ";" & row.Cells(1).ToString()
                line &= ";" & row.Cells(2).ToString()
                line &= ";" & row.Cells(3).ToString()
                line &= ";" & row.Cells(4).ToString()
                line &= ";" & row.Cells(5).ToString()
                line &= ";" & row.Cells(6).ToString()
                line &= ";" & row.Cells(7).ToString()

            Next
            sw.Flush()
            sw.Close()
        End If
    End Sub

And my columns in the gridview and also on the combo boxes ( I have the combo boxes displaying to the grid view)

Employee
(That holds a name)

Time In
(will hold the time they start a project) Ex: 8:15AM

Bay Number
(That holds bays 1, 2, 3, 4, or 5)

Customer Name
(Holds yet another name)

Estimated Project Time
(this will hold about how long it will take. Ex: 45 minutes)

Task
(Tells us what the heck they are doing LOL)

Status
(Where they are at with it. Ex: Waiting, In Progress..)

Finished Time
(will hold the time they are done with it) Ex: 10:00AM

And all the combo boxes that are on the left side of the grid..display the information to the Grid.

On my form under the combo boxes I have a Display button that when Hits..gets the combo text to the grid.

I have a refresh button so that when it is hit...it empties out the text in the combo box and another person can come and refill in their project info

and the save button, thats the one we have been working on

0

I said to myself what would happen if you just typed in the gridview and didnt use the combo boxes.

It did let me type in it. and I hit save..it gave me save dialog box..

I hit the x..to close because I do not have the save file dialog built in a menu yet.

It asked me if I wanted to exit without saving changes.

SO..do I need to activate the save file dialog in the menustrip?
and maybe recode the X closing on the form?

0

this is what I have for form closing when they hit that X LOL..

Private Sub frmMay1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If MessageBox.Show("Are you sure you want to exit without saving changes?", "Exiting", _
         MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
            e.Cancel = True
        End If
    End Sub

As I said a minute ago I dont have anything coded for the save function in the menustrip as yet.

but I think that it seems odd that after hitting the save button and then hitting the X...it would ask me if I wanna exit without saving changes

0

okay Thomas

what I thought was that for some reason the save button was not allowing my form closings to see that a save was made.

I went in and just tried to change Private Sub on the save button we have been working on to Public Sub. And it did allow me to do that without errors showing.

But alas..when It came time to close the form either by clicking on the X..or by closing using the menustrip Exit..both ways still asked me if I wanted to exit without saving changes.

so, this to me is where the error is LOL..it is in my closing codes, it really just has to be!

Can you do me a favor (as if you havent done enough!)and look at my closing code and maybe you can see where I screwed that up. Looks to me that maybe I didnt complete the code cuz even after using the save button we made the form will not acknowledge it

0

I've been looking through the code and have found a bunch of coding errors. My bad!

First, for this to work properly the DataGrid needs to have columns. Which you've added already.

Next, we need to revise the code for the last combobox.

Dim row As New DataGridViewRow 'The row object
        Dim cell As DataGridViewCell = New DataGridViewTextBoxCell 'The columns

        cell.Value = ComboBox1.GetItemText(ComboBox1.SelectedItem)
        row.Cells.Add(cell)

        cell = New DataGridViewTextBoxCell
        cell.Value = ComboBox2.GetItemText(ComboBox2.SelectedItem)
        row.Cells.Add(cell)

        cell = New DataGridViewTextBoxCell
        cell.Value = ComboBox3.GetItemText(ComboBox3.SelectedItem)
        row.Cells.Add(cell)

        cell = New DataGridViewTextBoxCell
        cell.Value = ComboBox4.GetItemText(ComboBox4.SelectedItem)
        row.Cells.Add(cell)

        ' And so on

        DataGridView1.Rows.Add(row)

We also need to add two lines to the SaveToFile method:

Private Sub SaveToFile(ByVal fileName As String)
        If DataGridView1.RowCount > 0 AndAlso DataGridView1.Rows(0).Cells(0) IsNot Nothing Then
            Dim stream As New System.IO.FileStream(fileName, IO.FileMode.Append, IO.FileAccess.Write)
            Dim sw As New System.IO.StreamWriter(stream)
            For Each row As DataGridViewRow In DataGridView1.Rows
                ' This makes sure that only rows with data in it gets read.
                If row.IsNewRow = False Then
                    Dim line As String
                    line = row.Cells(0).Value.ToString()
                    line &= ";" & row.Cells(1).Value.ToString()
                    line &= ";" & row.Cells(2).Value.ToString()
                    line &= ";" & row.Cells(3).Value.ToString()
                    line &= ";" & row.Cells(4).Value.ToString()
                    line &= ";" & row.Cells(5).Value.ToString()
                    line &= ";" & row.Cells(6).Value.ToString()
                    line &= ";" & row.Cells(7).Value.ToString()

                    ' This line was missing and also why the file was empty
                    sw.WriteLine(line)
                End If
            Next
            sw.Flush()
            sw.Close()
        End If
    End Sub

As for the form closing code.
The way you have coded it will always ask whether or not you would like to save.
Add a private class variable of Boolean type and in the save button click event, below the call to the SaveToFile method, change the boolean variable to True.

Private bIsFileSaved As Boolean = False

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim fileName As String = ""
        Dim dlgSave As New SaveFileDialog
        dlgSave.Filter = "Text files (*.txt)|*.txt|CSV Files (*.csv)|*.csv"
        dlgSave.AddExtension = True
        dlgSave.DefaultExt = "txt"
        If dlgSave.ShowDialog = Windows.Forms.DialogResult.OK Then
            fileName = dlgSave.FileName
            SaveToFile(fileName)
            bIsFileSaved = True
        End If
    End Sub

Then you can do this in your form closing event.

Private Sub frmMay1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    If bIsFileSaved = False AndAlso DataGridView1.RowCount > 1 Then
        If MessageBox.Show("Are you sure you want to exit without saving changes?", "Exiting", _
         MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
            e.Cancel = True
        End If
    End If
End Sub
0

good morning :)

I made the changes for all of it EXCEPT the revision to the combos. Cuz I dont know where I am suppose ta put it LOL...and up my butt is not an option!! heheheheee

I did the save closing and all of that and the stream writing.
the only thing I didnt do is this part

Dim row As New DataGridViewRow 'The row object        Dim cell As DataGridViewCell = New DataGridViewTextBoxCell 'The columns         cell.Value = ComboBox1.GetItemText(ComboBox1.SelectedItem)        row.Cells.Add(cell)         cell = New DataGridViewTextBoxCell        cell.Value = ComboBox2.GetItemText(ComboBox2.SelectedItem)        row.Cells.Add(cell)

is this suppose to ba attached to the combo boxes?? or the grid..

0

lol..
okay I just put that in the gridview itself..figured I wont break it if I tried it there LOL

and it did actually copy to excel :) YAYYYYYYYYYYY!!

but it all copied into 1 cell

all of the contents went into Cell A:1 hehehheeee

but at least it is now picking it up :)

0

Very nice. Progress!

I guess now, all you have to do is fidget with the SaveToFile method and try to see what happens if you replace the semi-colon with a comma.
Or see what happens if you first start Excel and open the CSV file from there.

Excel should automatically detect that it is a CSV file your opening and separate the fields into cells.

0

ahaaaaaaaaa! :)

me is tickled pink now!

I did change the colons to commas..and did save as a csv file. But then I went in and Set up fields in new sheet and saved it as a blank CSV file..LOL...( dont know why..but I did) AND then

Went back into studio and hit save again..save to the csv file i created a minute ago. When I went to save it, it told me to save in a different format so I could keep it intact...so I chose Workbook....BINGO!!! :)

Opened the saved work book and there it was..all nice and neat :)

Thank you so very much for all the time and patience, way above and beyond. SO...
where do you want me to send that pallet o beer too?? :)
And..it was nice to make a friend along the way.

Jenn

0

oboy...this is a dooooooooozy

after all that, I noticed something...

forgot a date field!!

this morning I tried to just throw a datetimepicker on the form and adding a date field to the grid for it to display to..*sigh*, well im sure you know that ended in disaster..LOL...cuz im using the info in combo boxes to display to grid...and datetimepicker is not a combo box.

so then I said okay..fine, I will just have them type the date in the field..well that didnt work either cuz even though the date was there...the combo selections decided to display in the line underneath it...

so then I said okay..lol...make a combobox with the dates in em...boy o boy...that worked good until ya opened excel up and in the dat field it was all #####.

SO..then I went into the date box and did this #5/1/2010#...and well, thats exactly what you saw in the dropdown LOL

Help??!!?? lol..I really dont wanna go asking around because by the time I take to explain just exactly what the situation is..I would have to start looking for visual studio 2020 by then LOL

OR..is this where the integer string comes in at.....

Edited by Dcurvez: added an idea

1

You can still have a DateTimePicker control on your form.
And if you wish it to be the last thing entered before adding data to the DataGrid, all you have to do is move the code previously in the SelectedIndexChanged event of the combobox into the ValueChanged event of the DateTimePicker.

When that is done, add these lines to the code that adds to the DataGrid.

cell = New DataGridViewTextBoxCell
        cell.Value = DateTimePicker1.Value.ToShortDateString
        row.Cells.Add(cell)

And also an additional line &= ";" & row.Cells(x).Value.ToString() to the SaveToFile method.

Edited by Oxiegen: n/a

Votes + Comments
this is by far more than ever expected..thank you 100000000000 hundred times over :)
0

awwwwwwwww thank ya so much!

lol...i been in a sheer panic,, pullin my hair out and dang near cried LOL..but then the thought of takin the whole computer out to the yard and putting a bullet through it kinda made me laff hysterically

heheheee

thank ya :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.