Listview save to a txt file - c#

I need that all data which I can see now in Find_ list View are online added to C:\Users\Public\WattLOG.txt file
Then I Will Access to this file with another program and read all events.
When there comes new line, I need to store it immediately in file.
private void Find_listView_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Search_listView_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}

Related

Cannot Read Write NFC C# using library

i have a coursework about nfc read and write, but i'm still new using C# and i found some libraries about nfc c#. one of them from h4kbas which I'm currenly using righ now.
the first thing i try is how to read UID, but it seem work fine
private void button1_Click(object sender, EventArgs e)
{
if (NFC.Connect())
{
textBox1.Text = NFC.GetCardUID();
}
}
and then i try making read and write :
Read
private void button2_Click(object sender, EventArgs e)
{
if (NFC.Connect())
{
NFC.WriteBlock(textBox2.Text, "5");
//Close();
}
}
Write
private void button3_Click(object sender, EventArgs e)
{
if (NFC.Connect())
{
NFC.ReadBlock("5");
//Close();
}
}
but after i try making a read and write function above, i don't found any error massage but if i try read or write some string data on running process, forced to close and give massage "The program '[10192] WFANFCReadWriteExecute.exe' has exited with code -1 (0xffffffff)." still..., i don't know the problem is on my code or i have to use "AuthBlock" first.

Checking if certain file\files exist

I want to make a windows form using C# to check if a file exist.
I've tried this one:
private void test_Click(object sender, EventArgs e)
{
var app1 = (#"C:\Users\frangon\Desktop\Spectrum-Check.EXE");
test.Text = File.Exists(app1).ToString();
}
If possible, I don't want to click it. I just want it to show as "True" if the file exist, or "False" if the file doesn't exist.
You can add an event to trigger when the form loads:
And then in your code behind:
private void Form1_Load(object sender, EventArgs e)
{
string app1 = #"C:\Users\frangon\Desktop\Spectrum-Check.EXE";
test.Text = File.Exists(app1).ToString();
}

C# Permanently Add and Save item to combobox

everybody!
I have collection of items in combobox's properties. And I want to add new item in my combobox by writing text in combobox and then use button event:
private void button2_Click_1(object sender, EventArgs e)
{
cbx_unix_dir.Items.Add(cbx_unix_dir.Text);
}
But in next time of starting my programm - my added item doesn't exist in combobox. What do I wrong? I need all added items have been saved in my combobox for ever. May be problem in method InitializeComponents()? May be I have to add event before it?
Thank you very much.
ComboBox has no functionality to save and reload items.
You may store items into .NET Settings file on closing window and reload them on loading form:
private void Form1_Load(object sender, EventArgs e)
{
if (Settings.Default.cboCollection != null)
this.cbx_unix_dir.Items.AddRange(Settings.Default.cboCollection.ToArray());
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
ArrayList arraylist = new ArrayList(this.cbx_unix_dir.Items);
Settings.Default.cboCollection = arraylist;
Settings.Default.Save();
}
//A button to add items to the ComboBox
private void button2_Click_1(object sender, EventArgs e)
{
cbx_unix_dir.Items.Add(cbx_unix_dir.Text);
}

Refresh DataGridView using BindingSource and TableAdapter

i actually work on a Customer-DataGrid but i stuck on the Sources because i dont use really often C#.
I have a DataGridView (dataGridView1), a internal Database (Database.mdf), a BindingSource (customerBindingSource) and customerTableAdapter
Now i trying to refresh the DataSource when i click a button.
Here is a simple snippet:
private void Kundenverwaltung_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'kundenAnsicht.customer' table. You can move, or remove it, as needed.
this.customerTableAdapter.Fill(this.kundenAnsicht.customer);
}
// I tried already some methods but i dont find a properly, functionally way
private void button2_Click(object sender, EventArgs e)
{
this.customerTableAdapter.Fill(this.kundenAnsicht.customer);
}
I hope you can understand my problem.
~ Dennis
You need to connect your DataGridView with "customerBindingSource":
`private void Kundenverwaltung_Load(object sender, EventArgs e)
{
this.dataGridView1.DataSource = this.customerBindingSource;
this.customerTableAdapter.Fill(this.kundenAnsicht.customer);
}
private void button2_Click(object sender, EventArgs e)
{
this.customerTableAdapter.Fill(this.kundenAnsicht.customer);
}`
It all.

Can you change the name of a C# Winforms button via the App.config file?

I have a Winforms app with buttons that when clicked go to various internal and external locations (Network locations/Web paths) I was asked if it was possible for the end users to have their own names for the buttons, instead of what I called them.
I've created an App.config file so if the links change they can at least edit that file reflecting the change in path/URL etc
The button properties text field doesn't appear to allow code behind it.
private void GoogleS_Click(object sender, EventArgs e)
{
try
{
string GoogleS = ConfigurationManager.AppSettings["Google"];
Process.Start(GoogleS);
}
catch (Exception GoogleErr)
{
MessageBox.Show(GoogleErr.Message);
}
}
And the key inside the App.config file
<add key="Google" value="http://www.google.com/" />
And the fix
App.config
<add key="GoogleButton" value="Google Search"/>
<add key="GoogleLink" value="http://www.google.com"/>
//Code for the Button names which are loaded on Form Loading from the App.config file
private void CSS_Load(object sender, EventArgs e)
{
btnGoogleS.Text = ConfigurationManager.AppSettings["GoogleButton"];
}
private void btnGoogleS_Click(object sender, EventArgs e)
{
try
{
string GoogleS = ConfigurationManager.AppSettings["GoogleLink"];
Process.Start(GoogleS);
}
catch (Exception GoogleErr)
{
MessageBox.Show(GoogleErr.Message);
}
}
private void btnGoogleS_MouseHover(object sender, EventArgs e)
{
System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
ToolTip1.SetToolTip(this.btnGoogleS, (ConfigurationManager.AppSettings["GoogleLink"]));
}
You can manually set the button captions:
btnGoogle.Text = ConfigurationManager.AppSettings["GoogleCaption"];
Probably you would do it in a Form Load handler.

Categories

Resources