Hi. Can anyone please help me? Following code create array of checklistboxes after user enter a value. I also have a json file:
{
"length": 38,
"masking": [ 1, 2, 6, 10, 15],
"date": "2018-08-07 10:10:10"
}
I want to be able to map user selection of checklistboxes to "masking" in json file. Also, how to assign values to arr of checkboxes e.g. checkbox[0] = A, checkbox[2] = B etc. We don't know how many checkboxes will be needed.
If user selects checkbox with indices 1, 3, 4, 6 it should map to json file and display value of selected checkboxes.
Thanks in advance.
SSMMasker.cs
- internal class SSMManager
- public SSMManager() { }
- {
- public int DataLength { get; set; }
- public int[] Masking { get; set; }
- public string Date { get; set; }
- public bool Save(string isFilename = null)
- {
- JObject ajsoncontent = new JObject(
- new JProperty("Datalength", DataLength),
- new JProperty("Masking", Masking),
- new JProperty("Date", Date)
- );
- if (isFilename == null) isFilename = SSMPositionManager.MASK_FILE;
- File.WriteAllText(isFilename, ajsoncontent.ToString());
- return true;
- }
- }
Form1.cs
- public partial class Form1 : Form
- {
- SSMPositionManager mcssmmanager = new SSMPositionManager();
- CheckedListBox acheckbox = new CheckedListBox();
-
- public Form1()
- {
- InitializeComponent();}
- private void btnCreate_Click(object sender, EventArgs e)
- {
- flPanel.Controls.Clear();
-
- int count = Int32.Parse(tbNumber.Text);
-
- for (int i = 0; i < count; i++)
- {
- CheckedListBox acheckbox = new CheckedListBox();
- string[] arr = {i + "th" };
- acheckbox.Items.AddRange(arr);
-
-
- acheckbox.Size = new Size(60, 40);
- acheckbox.Padding = new Padding(10, 10, 10, 10);
-
- flPanel.Controls.Add(acheckbox);
- }
- }
- private void btnSave_Click(object sender, EventArgs e)
- {
- SSMManager aMasker = new SSMManager();
- SSMPositionManager mcssmmanager = new SSMPositionManager();
- aMasker.DataLength = 40;
- aMasker.Masking = new int[] { 1, 4, 5, 6, 7, 8, 9, 10 };
- aMasker.Date = "2018-08-07 10:1mon0:10";
- listBoxIndex.Items.Clear();
-
-
-
- String[] itemArr = new string[acheckbox.CheckedItems.Count];
- Int32 counter = 0;
- foreach (object item in this.acheckbox.CheckedItems)
- {
- String temp = Convert.ToString(item);
- itemArr[counter] = temp;
- counter++;
- }
- }
- }