很抱歉有分歧,但今天我需要你的帮助......在C#中!我在这里找不到它。
对于下面的代码,我需要将CheckedItem ValueMember放入richtextbox或string var ...你能帮助我吗?
请注意LogBox是RichtTextBox,我想从checkitems中显示ValueMember。
// Favorites items
public class Favorites {
public string name { get; set; }
public string url { get; set; }
// For fav array in json
public class GetFav
{
public List<Favorites> favoris { get; set; }
}
// Member
public class ListBox
{
public string Text { get; set; }
public string Value { get; set; }
}
// Insert json data in CheckListBox
private void button2_Click_1(object sender, EventArgs e)
{
string fav = @"myjsonfile.json";
StreamReader sr = new StreamReader(fav);
string jsonString = sr.ReadToEnd();
var json = new JavaScriptSerializer().Deserialize<GetFav>(jsonString);
int i = 0;
for(i=0; i< json.favoris.Count; i++)
{
chkList.DisplayMember = "Text";
chkList.ValueMember = "Value";
chkList.Items.Insert(0, new {Text=json.favoris[i].name,Value=json.favoris[i].url});
}
}
// Need to get the ValueMember and DisplayMember
private void button3_Click(object sender, EventArgs e)
{
int i = 0;
for (i=0; i< chkList.CheckedIndices.Count; i++)
{
// logBox.Text += chkList.Items[i] + "\n"; show => { Text = Google, Value = google.fr }
//logBox.Text += (chkList.Items[i] as ListBox).Value + "\n"; //get an error
}
}
}