|
There's no "conversation"; there's nothing to "converse" over.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
By the way, you guys are coder or moderator?
|
|
|
|
|
Vigilantes
and Hell's comin' with us
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
If this is for a MVC app, there's plenty of info if you google this phrase: "mvc forgotten password".
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I am trying to create a function in the GUI where I Logg the values from a textbox and then allow the user to save these values as a .csv file anywhere on the computer.
I have managed to do that, but when I open the files I only see one item from my textbox written in the text file, Why is that ?
private void Logging()
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
using (Stream s = File.Open(saveFileDialog1.FileName, FileMode.CreateNew))
using (StreamWriter sw = new StreamWriter(s))
{
sw.WriteLine(textSampling.Text);
}
}
|
|
|
|
|
You are using File.Open(saveFileDialog1.FileName, FileMode.CreateNew) every time, so the file will only ever contain that last item logged. You need to use FileMode.Append as described at FileMode Enumeration (System.IO)[^].
|
|
|
|
|
Hi, how am I suppose to implement it with my code.
i have code that is doing almost everything I want, only not printing the contents from the text.Box. The strange thing is, when I use a RichTextBox then everything gets printed into the .csv file I am trying to create.
Were you thinking about something like this?
private void Logging()
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
using (Stream s = File.Open(saveFileDialog1.FileName, FileMode.CreateNew | FileMode.Append))
using (StreamWriter sw = new StreamWriter(s))
{
sw.WriteLine(textSampling.Text);
}
}
|
|
|
|
|
I already explained, that if you use FileMode.CreateNew you will be creating a new file every time you try to write a log entry. You only need to use that once, at the beginning of a session perhaps*, and use FileMode.Append for every subsequent call.
* You need to use some sort of file name cycling in your programs so you do not overwrite the previously created files. A common method of doing this is to create files with the date as part of the filename.
|
|
|
|
|
For "simple" logging, all you need is:
1) File.AppendAllText, or
2) File.AppendAllLines
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Itried that but it didnt work
|
|
|
|
|
What is "it"?
If it didn't work, you did "it" wrong.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Yes you are completely correct . I did something very WRONG.
Holy Sh*t , I was writing from wrong text box the whole time.
My initial code actually works;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
using (Stream s = File.Open(saveFileDialog1.FileName,FileMode.CreateNew))
using (StreamWriter sw = new StreamWriter(s))
{
sw.WriteLine(textSensorValues.Text);
}
}
|
|
|
|
|
Been there, done that.
One "relaxes" AFTER the problem is solved; not before.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
<label class="col-sm-2 control-label">Vehical Mileage<span style="color:red">*</span></label>
<div class="col-sm-10">
<input type="text" name="mileage" class="form-control" required>
$query->bindParam(':mileage',$mileage,PDO::PARAM_STR);
the above is a code im using to insert data into the mileage row, im creating a car rental system, i was wonder if anyone could help me with a code that can relate to the mileage.
say the mileage is about to reach 1000,
when the mileage reaches one thousand the status should change to IN SERVICE.
|
|
|
|
|
Sounds like "if this, then that". Just "bind" to something that says "IN SERVICE" or (not) in service, or whatever. Even "blank" is an option. Or "hide" the element ... jeez.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
That doesn't look anything like C#.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
So why have you posted it in the C# forum?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm trying to make a ToDo app but I'm stuck. I did a UserControl named Item that consists of a panel which includes a checkbox, a textbox and a button: [^]
The problem is that I don't know how to manage those dinamically generated items. For instance, if I delete one item by pressing that X button (I call the method Dispose on DeleteButton_Click ), how could I arrange the remaining items in order to be one after another? See this screenshot: [^]
Any advice?
modified 11-Feb-18 19:32pm.
|
|
|
|
|
How about trying the FlowLayoutPanel in the Toolbox.
|
|
|
|
|
Calling Dispose doesn't remove anything from anywhere, it just closes down and releases any resources the object used - which means that just calling Dispose on objects in the display will not only not work, but is very liable to throw an ObjectDisposedException[^] when it gets subsequently looked at.
Start by looking at how you add new objects, because that is where you need to delete them: an object can't delete itself, because it doesn't (or shouldn't) know what container it is held in.
If you add them to a panel:
Item item = new Item();
myPanel.Controls.Add(item); Then you need to remove them from the panel:
myPanel.Controls.Remove(item);
item.Dispose(); But it's going to be similar for all other containers.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi, Griff,
Calling 'Dispose on a WinForm Control will remove it from its container.
However, as you state, that is not best practice.
cheers, Bill
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
Hi Bill!
Thanks for that. It does if you call the bool version (which I didn't know), but it doesn't if you call "vanilla" Dispose :
void IDisposable.Dispose() {
if (hBitmapDC.Handle == IntPtr.Zero || hMetafileDC.Handle == IntPtr.Zero || hBitmap.Handle == IntPtr.Zero) {
return;
}
bool success;
try {
success = DICopy(hMetafileDC, hBitmapDC, destRect, true);
Debug.Assert(success, "DICopy() failed.");
SafeNativeMethods.SelectObject(hBitmapDC, hOriginalBmp);
success = SafeNativeMethods.DeleteObject(hBitmap);
Debug.Assert(success, "DeleteObject() failed.");
success = UnsafeNativeMethods.DeleteCompatibleDC(hBitmapDC);
Debug.Assert(success, "DeleteObject() failed.");
}
finally {
hBitmapDC = NativeMethods.NullHandleRef;
hBitmap = NativeMethods.NullHandleRef;
hOriginalBmp = NativeMethods.NullHandleRef;
GC.SuppressFinalize(this);
}
}
Reference Source[^]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi, Griff,
Strange, I just checked in VS 2017, FrameWork 4.7.1, and the vanilla no-param version did remove the Control.
TextBox tbx = new TextBox { Text = "wtf" };
this.Controls.Add(tbx);
var c1 = this.Controls.Count;
tbx.Dispose();
var c2 = this.Controls.Count;
bool isnull = tbx == null;
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
So the reference sources aren't the source code to .NET? Ouch!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|