Save RTB text to specific CSV cell

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 2 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Save RTB text to specific CSV cell

Post by localpct »

Hello,
I have a CSV file as such
User, Number, Notes
Test, 1, Office on 2nd Floor.

Can I type text into a richtextbox and have it formatted and saved to a CSV?
richtextboxquestion.png
richtextboxquestion.png (5.27 KiB) Viewed 3179 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Save RTB text to specific CSV cell

Post by jvierra »

Not necessar4y and very difficult for any beginner. Use a DataGridView,
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Save RTB text to specific CSV cell

Post by localpct »

Why a DGV?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Save RTB text to specific CSV cell

Post by jvierra »

It can load and edit a CSV directly.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Save RTB text to specific CSV cell

Post by jvierra »

Here is a starter demo:
Attachments
Demo-DGVExport.psf
(18.97 KiB) Downloaded 86 times
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Save RTB text to specific CSV cell

Post by localpct »

I see how it can load and edit the CSV directly.

How do I use the export button for a specific cell? In the ISE, I can do something like this

$NewNotes = 'This is an appended note'
(Import-Csv $CSV | Where-Object {$_.samaccountname -eq 'jones'}).notes |foreach{{$_.Notes = + $NewNotes}}

Using the form as is, it produces a new line
richtextboxquestion.png
richtextboxquestion.png (7.19 KiB) Viewed 2973 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Save RTB text to specific CSV cell

Post by jvierra »

It is impossible to understand wha5t you are asking. You cannot export one cell to a whole CSV. You can export a collection of rows with one or more cells to a CSV.

Your description and question do not have enough or correct informatiuon to tell us what your issue is.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Save RTB text to specific CSV cell

Post by localpct »

Remember from earlier, I'm trying to build a Notes section which is just a new column in the CSV
So within my app, I'm only displaying ONE cell, which is the notes cell
  1. $Notes = Import-Csv 'C:\Users.csv' | Where-Object {$_.Shortname -eq 'jones'} | Select-Object Notes
  2.     $datagridview1.DataSource = ConvertTo-DataTable $Notes
This will display the notes cell. I want to add new notes into the cell, so what code do I put in the $buttonExportCsv_Click block to update the CSV
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Save RTB text to specific CSV cell

Post by jvierra »

You have to load teh whole CSVinto the DGV, edit the specific cell and save the whole CSV.

Second option. Load teh CSV, find the cell, display, edit it, update teh CSV, save the whole CSV.

Third option: loaqd teh CSV as a Data object, edit cell, update object which will update the cell in the CSV file.
User avatar
localpct
Posts: 397
Last visit: Thu Oct 27, 2022 5:57 am

Re: Save RTB text to specific CSV cell

Post by localpct »

Correct
Number 2 is what I'm using - or should I say trying to :)

I can say if I create the CSV it works as expected, but if I import it, everything gets erased but the column name, and the notes. So my guess is that I'm finding it and displaying it incorrectly.
This topic is 2 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked