using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
Dictionary<Prime_Broker, Margin2> myDictionary = new Dictionary<Prime_Broker, Margin2>();
public Form1()
{
InitializeComponent();
Prime_Broker pr1 = new Prime_Broker("Deutsche Bank", "z", "india");
Prime_Broker pr2 = new Prime_Broker("Deutsche Bank1", "z", "india");
Prime_Broker pr3 = new Prime_Broker("Deutsche Bank2", "z", "india");
Prime_Broker pr4 = new Prime_Broker("Deutsche Bank3", "z", "india");
Prime_Broker pr5 = new Prime_Broker("Deutsche Bank4", "z", "india");
Margin2 mr1 = new Margin2(30, 40, 50);
Margin2 mr2 = new Margin2(301, 40, 50);
Margin2 mr3 = new Margin2(302, 40, 50);
Margin2 mr4 = new Margin2(303, 40, 50);
Margin2 mr5 = new Margin2(304, 40, 50);
//myDictionary.Add(new Prime_Broker("Deutsche Bank", "z", "india"), new Margin2(30, 40, 50));
//myDictionary.Add(new Prime_Broker("Deutsche1 Bank", "z", "india"), new Margin2(301, 40, 50));
//myDictionary.Add(new Prime_Broker("Deutsche2 Bank", "z", "india"), new Margin2(302, 40, 50));
//myDictionary.Add(new Prime_Broker("Deutsche3 Bank", "z", "india"), new Margin2(303, 40, 50));
myDictionary.Add(pr1, mr1);
myDictionary.Add(pr2, mr2);
myDictionary.Add(pr3, mr3);
myDictionary.Add(pr4, mr4);
myDictionary.Add(pr5, mr5);
}
public class Prime_Broker
{
public string Name { set; get; }
public string Symbol { set; get; }
public string Address { set; get; }
public Prime_Broker(string name, string symbol, string address)
{
this.Name = name;
this.Symbol = symbol;
this.Address = address;
}
}
public void Form1_Load(object sender, EventArgs e)
{
List<Prime_Broker> lst_broker = new List<Prime_Broker>();
lst_broker.Add(new Prime_Broker("Deutsche Bank", "z", "india"));
lst_broker.Add(new Prime_Broker("Deutsche1 Bank", "z", "india"));
lst_broker.Add(new Prime_Broker("Deutsche2 Bank", "z", "india"));
lst_broker.Add(new Prime_Broker("Deutsche3 Bank", "z", "india"));
listBox1.DataSource = lst_broker;
listBox1.DisplayMember = "Name";
listBox1.ValueMember = "name";
//listBox1.Items.AddRange(lst_broker.ToArray());
dataGridView1.DataSource = lst_broker;
}
public class Margin2
{
public int Maintainence_margin { set; get; }
public int Initial_margin { set; get; }
public int Commission_fees_percentage { set; get; }
public Margin2(int M_margin, int I_margin, int CF_Percentage)
{
this.Maintainence_margin = M_margin;
this.Initial_margin = I_margin;
this.Commission_fees_percentage = CF_Percentage;
}
}
public void listBox1_SelectedValueChanged(object sender, EventArgs e)
{
Form1 fr = new Form1();
//List<fr.myDictionary> lst_broker = new List<Prime_Broker>();
}
}
}
你好
这是我正在尝试将数据添加到列表框的代码,现在我想将列表框的选定索引的字典数据显示到文本框但无法执行。如何将字典数据绑定到列表框和新的 texbox
像这里如果我选择“deutchBank1”,那么现在文本框将包含(301、40、50)。