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);
}
Related
I've working on a C# Forms application, the MainScreen contains a DataGridView in which the first row is an auto-generated incremented number. When manually coding data into the DataGridView, I'm able to set this ID field with the incremented number.
What I'm trying to do now is create an "Add" form, I need the first text box to be populated with the next incremented number when it opens.
What is the simplest way to know what the current last number used in the DataGridView is?
For example, if I have 2 rows, obviously the new "Add" row would have an ID of 3, but how can I code the Text box to dynamically grab that information and increment +1 each time the form is opened?
Edit:
To provide more context, I will have a button for Add, and a button for Modify. The modify button will not open the Modify form unless a row is selected. Here is my code to populate the text box on the modify form, based on the selected row:
ModPartIDBox.Text = Inventory.AllParts[Inventory.CurrentIdxPrt].PartID.ToString();
The "Add" form obviously doesn't check and doesn't care if a row is selected, so I can't lean on just calling that already filled field, so I just need a way to grab highest number.
Keep a list of all objects that you are going to store in your DataGridView so you can access their data later on, such as:
var items = new List<MyObject> {}
Where MyObject looks a little something like this:
public class MyObject
{
public int PartId { get; set; }
}
and then when you need to pull the highest number, you can use a LINQ expression:
int highestNumber = items.OrderByDescending(x => x.PartId).First().PartId;
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
I have 3 text boxes and one button. On button click all text from text boxes should be written in text file (in one line). How can i do that?
Direct implementation:
File.WriteAllText(dest,
tbID.Text + tbIme.Text + tbPrezime.Text);
You can have all textboxes in a List<TextBox> and at the time of writing do:
list.ForEach(tb => file.Write(tb.Text));
file.WriteLine();
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'm writing an analyzer,which shows the packets of a specific program.Some packets are very large and the listview shows only the first 15-20 characters :\
This is my code
string __str = String.Join(" ", data.Select(x => x.ToString("x2")).ToArray()); //covert the byte[](packet) to hex string
string __ascii = AsciiToString(data); //convert the byte[](packet) to ASCII
if (encrypted) FormMain.PFA(form => form.listViewAnalyzer.Items.Add("S<-C [ENCRYPTED] Blowfishkey = 0xFF"));
else FormMain.PFA(form => form.listViewAnalyzer.Items.Add("S<-C"));
ListViewItem item = new ListViewItem(__str); //create new item and place the packet as hex string
item.SubItems.Add(__ascii); //add the ascii variant as substring
FormMain.PFA(form => form.listViewAnalyzer.Items.Add(item)); //add the item
It must be a property that prohibits adding text with more than x lines,but I can't see it.
The listview will contain all the text, you just can't see it if it's too long or has multiple lines.
The way that Outlook and things like packet sniffers often work is that the listview is accompanied by a textbox or "preview" window. You could change your UI so that selecting the item in the listview displays the full details of the item in an outlook-style preview pane. Then you could have a large multiline textbox and anything else you wanted. I often do this by putting an object in the ListViewItem.Tag property, so that I can retrieve it in the UI and display in the preview when the ListView.SelectedIndexChanged event fires.
Alternatively, the preview could be on a dialog that pops up when you double-click. In fact, make the preview UI a UserControl, then you can do both!
listview shows only the first 15-20 characters :\
Maybe you need to make the column wider?
It must be a property that prohibits adding text with more than x lines,but I can't see it.
List view items don't wrap text, so technically they prohibit text with more than 1 line