TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ayush sid
NA
5
578
Stuck with CheckedListBox
Aug 29 2018 6:21 AM
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;
// public static string MASK_FILE = "masking.json"; in SSMPositionManager.cs
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);
//entered text
for
(
int
i = 0; i < count; i++)
{
CheckedListBox acheckbox =
new
CheckedListBox();
string
[] arr = {i +
"th"
};
acheckbox.Items.AddRange(arr);
//acheckbox.Text = i + "th"; //initially the button is selected to be this val
acheckbox.Size =
new
Size(60, 40);
acheckbox.Padding =
new
Padding(10, 10, 10, 10);
//acheckbox.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
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();
//gives index of the selected box
//checkedlistbox to a string array (items which has been checked in checkedlistbox to store in a string array)
////if (acheckbox.Items.Count > 0)
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++;
}
}
}
Reply
Answers (
0
)
IEnumerable Interface
how to substract two value in two tables in sql database