I have a winform app that has 25 buttons that increase a counter on 25 labels above each button. What would be the best way to use a save button on click event to save the current values of the labels to a comma-delimited text file such that the first save creates the file and each additional save overwrites it?
Info: Assume the labels are named label1-label25 for simplicity, the text file will be named appDataFile, and that the save button will be named button26.
Example: On initial save, the winform app will create appDataFile and populate 25 values separated by commas. On any additional save it will then take the current value (let's say label1 was 5 already and its new value is 7) and will then overwrite the data in the text file and be left still with 25 values but the first being label1 will now be 12
Related
I'm in the process of creating a front-end Windows Forms application, which will have multiple uses. One of those uses will be to allow the end-user to manage the contents of a database table.
At the moment, my form contains a DataGridView object which uses a DataTable as its source. That datatable is populated from a stored procedure which selects every row from the table based on criteria specified by the end user. I want to put code into the DataGridView which will look at the row that's been selected by the user, and will populate a series of text boxes with the details from that row.
I want to avoid hard-coding a text box for each column in the DataGridView, since it's highly possible that in the future I might add columns to the underlying stored procedure. Therefore, my plan is that the first time the user selects a row, the application would dynamically create a text box for each column, size that text box appropriately (both height and width) and add the appropriate labels.
So far, the code I've written creates a brand-new DataTable, and adds columns to store the following information about each column in the DataGridView:
The actual name of the DataGridView column;
The name that I wish to give to the associated label;
The text that I wish to assign to the associated label;
The top and left positions of the associated label;
The name that I wish to give to the associated text box;
The value that I wish to display in the associated text box;
So far when the user initially clicks on a row, everything is working well: the text boxes get created in a vertical column, with the associated label to the left of each text box and the appropriate value displayed in each one. Each text box has its width dynamically set based on the contents of that text box so that everything can easily be seen.
The difficulty comes when the user changes from one row of the DataGridView to another. The code that runs to create each control looks like this:
if (pnlManageJobManagerOutcomes.Controls.Contains(txtCurrent))
{
pnlManageJobManagerOutcomes.Controls.Remove(txtCurrent);
}
if (!pnlManageJobManagerOutcomes.Controls.Contains(txtCurrent))
{
pnlManageJobManagerOutcomes.Controls.Add(txtCurrent);
}
When the code first runs, all seems to be fine. However, if it gets fired a second time (at which point it should remove and re-create the control) it doesn't seem to detect the prior existence of the control and simply creates a second copy of it in the form.
For information, the form I'm building has multiple uses which are dictated by a series of buttons. Therefore, I'm creating the controls for this particular use inside a Panel (pnlManageJobManagerOutcomes). I'm completely stumped as to why the code doesn't spot the existence of those controls during subsequent executions.
TIA
I've figured out a way to do it, which may seem to be clunky but which seems to work.
Since it doesn't appear that I can check to see whether the Panel I'm working with Contains the field name, I've written a method which will loop through the controls in that Panel and return a count of the number of instances of that control in the Panel's Controls array. If the method returns a 0, this means the Control doesn't exist in that Panel and I can go ahead and create it.
I have a text file in which I am getting data (per line) and loading it into an array. I'm wondering if it's possible to use the array (1 per line) to name the buttons (10+ buttons) I have.
My goal is: Form 1 loads with multiple buttons on screen, form 2 will have data on it which changes the button text on form 1. I save a text file of all button text on form 1. When I reload the form, I'm wanting it to read from the text file with the saved changes and load those button names to it.
I have it saving the button text + loading the text file to an array, but how do I use the values from the array to change the buttons text for each button.
At the moment, it's only changing 1 button text to the whole array list I created.
string[] lines1 = System.IO.File.ReadAllLines(#"C:\CSharp\important.txt");
foreach (var item1 in lines1)
{
b1112.Text = item1;
MessageBox.Show(item1);
}
I have a productlabel (.lbl file crated with NiceLabel).
Using Wingforms (c#) I want to open this label file and get the fields so I can assign data (from my database) to them and then save the label.
So in the end, I have a label with values that I can print.
Is a way t do this?
Edit: If possible, it would be awesome to also show the finished label in the form, to see if all values are in correct place.
I've created a C# Windows Forms application in .NET. It has a main form. Main form has a ListView control with four columns as below:
First Name
Last Name
Age
Gender
I populate the list view with 1 row with following values
First Name - Rasik
Last Name - Bihari
Age - 32
Gender - Male
Here is the screenshot:
I'm trying to test its accessibility for specially-abled users through JAWS screen reader tool. The issue is that whenever I select one of the rows it reads only the value of all the column values one by one. It doesn't read the header text along with it. My expectation is that it should read like -
First Name : Rasik
Last Name : Bihari
Age : 32
Gender : Male
JAWS support some keyboard shortcuts to have this behavior explicitly. Like if you press Insert + Ctrl + 1 then it will read the value of first column like this -
First Name : Rasik
If you press Insert + Ctrl + 2 then it will read the value of second column like this -
Last Name : Bihari
I want this behavior by default so that as soon we select a row in the ListView control i.e. it should read the entire row in 'column header text' : 'column value' pairs.
Does anyone has any clue on this if there is any property of listView control which need to be set or any setting in JAWS which can be of help?
If you are looking for a sample behavior then open Visual Studio -> Go to Debug Menu -> Click Attach to Process menu item. In Attach to Process window there is a group box Available Processes which shows the list of all available processes to which you can attach your code. It is also a ListView control. When I run JAWS with Visual Studio, on this window it reads all the column header text and column value pairs one by one when I select a row by mouse. I expect the same behavior for my application also.
But on the same machine JAWS is behaving differently for my application.
I was able to figure this out myself. There was no additional coding required to achieve it. Actually JAWS by default suppresses this reading behavior through its configuration. You need to configure JAWS explicitly to read the rows of a list view in <Column Header> - <Column Value> fashion.
When your application is running and the current focus is on a list view control on the form being displayed, press JAWS KEY + F2. It opens JAWS manager popup showing a list of what all items can be configured. Choose second option Customize ListView and press OK (Refer screenshot):
On the Customize Headers window you will see that currently Ignore radio button is selected (Refer screenshot):
Change the radio button selection to the appropriate option to alter the screen reading behavior for ListView control.
The most irritating issue is that this configuration needs to be done separately for every list view control appearing in your application. There is no centralized mechanism to configure it in one go for your entire application.
Note: Since by default JAWS is configured to read only column values, this means that it is appropriate for specially abled users. Freedom scientific must have researched around it as reading the column headers might be extraneous/trivial information which is not desired at once.
Also, if the specially abled user wants to read the column headers then JAWS KEY + Ctrl + Column Header Index keyboard shortcut is always available to read it in that format.
Note: Different screen reader tools like Thunder, NVA behave differently while reading a ListView.
I was wondering if somebody knows the right approach to save the position of reordered items in a listbox to a SQLitedatabase so when the wpf app opens next time it shows the saved order.
Where do I save the order and how does it update the database when I change the position of the items in the listbox again.
1- define a column in table called sequence or any suitable name you like
2- when you fetch data from database, always order by this field
3- when you change in app, you have two options
- you change the order on every change event that can be too many calls to database
- once you are done with ordering, you can have a save button or on leave event of the screen and send the data to database with the order and just set the sequence in database.
This way next time you get it, it will be saved sequence.