14,667,145 members

# Comments by Shaheer Rizwan (Top 41 by date)

Shaheer Rizwan 4-Aug-20 7:05am View

yea it was the code you put. Idk why but it messed up, I tried a bit of modification and it finally worked
Shaheer Rizwan 4-Aug-20 6:47am View

Well I fixed it! Thanks mate. But now, when I multi-select rows, it writes both lines on the same line. Please, dont air it, just suggest what I can do here. And I know your not tryna be nasty, im just really stressed cause this project is due on Friday, and i've been juggling other subjects and yea its just stressful
Shaheer Rizwan 4-Aug-20 5:53am View

yea ive been trying for ages. I thought id get some help as im struggling.
Shaheer Rizwan 4-Aug-20 5:25am View

Ive tried changing it to False, when I changed it to false, every time I added a new selected row to the file, it'll completely rewrite the file and the original rows I seleted would not be there. Therefore, I set it to true, which doesn't overwrite the file, but now its writing the headers as well.
Shaheer Rizwan 1-Aug-20 4:40am View

Do you know how I fix this though, (ive tried alot of things).
Say I select the 10th row, and write it to the file, it gets written to the 10th line despite nothing else in the file, how can I get it so it writes to the next available line, except of just what row number it is on the DataGridView
Shaheer Rizwan 1-Aug-20 4:38am View

Yeah got it thanks mate.
Shaheer Rizwan 30-Jul-20 20:02pm View

Well i did something and got it
Shaheer Rizwan 30-Jul-20 7:12am View

Also Im sorry for bothering you so much im just stressed and need this project done :(
Shaheer Rizwan 30-Jul-20 7:11am View

how would i call this underneath a Button Click event. I know you call it by e.ColumnIndex = when its an event relating to the DataGridView.
Shaheer Rizwan 30-Jul-20 6:31am View

Deleted
the thing is, Im selecting it by the checkbox, clicking the button, but no success. Im also checking by opening the CSV and it contains only what I originally wrote to it
Shaheer Rizwan 30-Jul-20 6:26am View

yeah the 8th column, clmSelected
Shaheer Rizwan 30-Jul-20 6:18am View

I used this code, I get that if I make clmSelected.Selected = True, I have to run the loop. How do I get it to skip, If clmSelected.Selected = True then...

Private Sub btnToSession_Click(sender As Object, e As EventArgs) Handles btnToSession.Click
'Write to Session.csv to load into that Form easily
'Only selected value's via clmSelected
Dim StrExport As String = ""
For Each C As DataGridViewColumn In dataGVGeneral.Columns
StrExport &= """" & C.HeaderText & ""","
Next
StrExport = StrExport.Substring(0, StrExport.Length - 1)
StrExport &= Environment.NewLine

For Each R As DataGridViewRow In dataGVGeneral.Rows
'If clmSelected.Selected = True Then
For Each C As DataGridViewCell In R.Cells
If Not C.Value Is Nothing Then
StrExport &= """" & C.Value.ToString & ""","
Else
StrExport &= """" & "" & ""","
End If
Next
StrExport = StrExport.Substring(0, StrExport.Length - 1)
StrExport &= Environment.NewLine
'If clmSelected.Selected = False Then
Next
Dim tw As System.IO.TextWriter = New System.IO.StreamWriter("E:\SAT\Work.io\Work.io\bin\Debug\Session.csv", False)
tw.Write(StrExport)
tw.Close()
End Sub
End Class
Shaheer Rizwan 30-Jul-20 6:15am View

I just get stuck when it comes to actually implementing the stuff
Shaheer Rizwan 30-Jul-20 6:07am View

can you give me a clue or something man im really stuck :(
Shaheer Rizwan 30-Jul-20 6:02am View

its just not working and im confused man
Shaheer Rizwan 30-Jul-20 4:01am View

well i tried this and just no luck, I put the it before the For Loops, no luck.

Dim StrExport As String = ""
For Each C As DataGridViewColumn In dataGVGeneral.Columns
StrExport &= """" & C.HeaderText & ""","
Next
StrExport = StrExport.Substring(0, StrExport.Length - 1)
StrExport &= Environment.NewLine
If clmSelected.Selected = True Then
For Each R As DataGridViewRow In dataGVGeneral.Rows
For Each C As DataGridViewCell In R.Cells
If Not C.Value Is Nothing Then
StrExport &= """" & C.Value.ToString & ""","
Else
StrExport &= """" & "" & ""","
End If
Next
StrExport = StrExport.Substring(0, StrExport.Length - 1)
StrExport &= Environment.NewLine
Next
Dim tw As System.IO.TextWriter = New System.IO.StreamWriter("E:\SAT\Work.io\Work.io\bin\Debug\ListofTasks.csv", False)
tw.Write(StrExport)
tw.Close()
EndIf
Shaheer Rizwan 30-Jul-20 3:40am View

Im just newbie man. I get confused by what does what even though ive read it a million times.

Anyways, will this work

For Each R As DataGridViewRow In dataGVGeneral.Rows
If clmSelected.Selected = True Then
For Each C As DataGridViewCell In R.Cells
If Not C.Value Is Nothing Then
StrExport &= """" & C.Value.ToString & ""","
Else
StrExport &= """" & "" & ""","
End If
Next
StrExport = StrExport.Substring(0, StrExport.Length - 1)
StrExport &= Environment.NewLine
End If
Next
Shaheer Rizwan 30-Jul-20 3:32am View

sorry, im a bit of a slow learner and noob. well thanks for this, will the
If clmSelected.Selected = True
Then
statement, before StrExport = StrExport.Substring(0, StrExport.Length -1)?
Shaheer Rizwan 29-Jul-20 19:36pm View

can that be via the checkbox column. say if i checked it, and pressed a button, that data will be copied over to another DataGridView in another form. Is there some sample code I can find somewhere, I am really stuck
Shaheer Rizwan 29-Jul-20 3:53am View

Via a button click
Shaheer Rizwan 28-Jul-20 7:12am View

Ok ill try that thanks
Shaheer Rizwan 27-Jul-20 23:37pm View

Check above for the exact code
Shaheer Rizwan 27-Jul-20 23:33pm View

Hey mate, I just tried this again, and its not overwriting the whole file and is duplicating the records already present after loading it. Is there another way. Sorry to bother you im just a bit stuck
Shaheer Rizwan 27-Jul-20 22:03pm View

Is there a way to clear the CSV file and rewrite its contents based on the DataGridView.

Can I use something like this and then simply add the clear CSV line?

``` Private Sub btnExportData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExportData.Click Dim StrExport As String = "" For Each C As DataGridViewColumn In DataGridView1.Columns StrExport &= """" & C.HeaderText & """," Next StrExport = StrExport.Substring(0, StrExport.Length - 1) StrExport &= Environment.NewLine For Each R As DataGridViewRow In DataGridView1.Rows For Each C As DataGridViewCell In R.Cells If Not C.Value Is Nothing Then StrExport &= """" & C.Value.ToString & """," Else StrExport &= """" & "" & """," End If Next StrExport = StrExport.Substring(0, StrExport.Length - 1) StrExport &= Environment.NewLine Next Dim tw As IO.TextWriter = New IO.StreamWriter("C:\Test1.CSV") tw.Write(StrExport) tw.Close() End Sub <code>```
Shaheer Rizwan 26-Jul-20 8:55am View

yeah I will :) lol
Shaheer Rizwan 26-Jul-20 8:53am View

The main problem wasn't actually with the code (semi). First I removed the try statements, then I changed a column which was a combobox to a normal textbox and it worked. I'm just going to validate that column to only accept numbers now.
Shaheer Rizwan 26-Jul-20 8:51am View

Nvm I fixed it. Although I couldn't understand it at first it was actually very helpful. Thanks man
Shaheer Rizwan 26-Jul-20 8:49am View

I ran it without all the try stuff and this came up https://imgur.com/a/a7hUv17
Shaheer Rizwan 26-Jul-20 8:44am View

I ran it by removing the Try statements, and this came up: https://imgur.com/a/a7hUv17
Shaheer Rizwan 26-Jul-20 8:16am View

well i ran the debugger and went through it, and i still cant figure it out
Shaheer Rizwan 26-Jul-20 8:04am View

so... should I try something else except of Try? Im a bit of a noob when it comes to coding and its for an assignment so im stressing so sorry if I wasn't thorough with explaining my problem
Shaheer Rizwan 26-Jul-20 7:59am View

yes, there's actually 13 more lines in the CSV file. I've got no idea why it isnt printing the rest
Shaheer Rizwan 22-Jul-20 20:00pm View

Is there a way to just save all the inputted data in any file and then select a row via the checkbox column and send that row to another datagridview in another form and save it?
Shaheer Rizwan 22-Jul-20 2:03am View

Thank you I'll have a look
Shaheer Rizwan 18-Jul-20 3:47am View

Thanks I'll have a look
Shaheer Rizwan 16-Jul-20 19:39pm View

I should make a point that I actually have a DataGridView desgined with headers (column headings) and don't want to change it. I simply want it so when the textboxes are filled in and confirmed and the Task is added to the DataGridView, for it to save to the CSV file (or XML or Text), and load automatically when the program is then opened. I also want it for a selected row (via the dataGridViewCheckBoxColumn) to be moved to another DataGridView in another form.
Shaheer Rizwan 16-Jul-20 19:30pm View

Should I instead save the DataGridView Rows as Textfiles, which are seperate for each DataGridView I have. The main problem I am having is figuring out how I can get a selected row to be sent to another DataGridView in another form
Shaheer Rizwan 10-Jul-20 2:36am View

I changed up the question, now I want it to go directly to a reminder when a button is clicked, whereas previously I wanted it to go to a DataGridView and then create it
Shaheer Rizwan 9-Jul-20 6:19am View

Thank you, I will have a look! Sorry I am abit of a newbie when it comes to programming in general.
Shaheer Rizwan 9-Jul-20 3:51am View

I have added the code I used, and what I want to achieve exactly
Shaheer Rizwan 9-Jul-20 3:36am View

@RickZeeland - Im looking to have a msgBox pop up with the Task Name value pop-up