Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
- MyBase.OnLoad(e)
- For i As Integer = 1 To 3
- Dim tempInfo As New NumberInfo()
- tempInfo.Count = i
- tempInfo.Number = i * 100
- ListBox1.Items.Add(tempInfo)
- Next
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- For Each objItem As Object In ListBox1.Items
- Dim info As NumberInfo = DirectCast(objItem, NumberInfo)
- info.Count += 1
- Next
- End Sub
- End Class
- Public Class NumberInfo
- Public Count As Integer
- Public Number As Integer
- Public Overrides Function ToString() As String
- Return String.Format("{0}, {1}", Count, Number)
- End Function
- End Class
- using System;
- using System.ComponentModel;
- using System.Windows.Forms;
- namespace TestBindingList
- {
- public class Employee
- {
- public string Name { get; set; }
- public int Id { get; set; }
- }
- public partial class Form1 : Form
- {
- private BindingList<Employee> _employees;
- private ListBox lstEmployees;
- private TextBox txtId;
- private TextBox txtName;
- private Button btnRemove;
- public Form1()
- {
- InitializeComponent();
- FlowLayoutPanel layout = new FlowLayoutPanel();
- layout.Dock = DockStyle.Fill;
- Controls.Add(layout);
- lstEmployees = new ListBox();
- layout.Controls.Add(lstEmployees);
- txtId = new TextBox();
- layout.Controls.Add(txtId);
- txtName = new TextBox();
- layout.Controls.Add(txtName);
- btnRemove = new Button();
- btnRemove.Click += btnRemove_Click;
- btnRemove.Text = "Remove";
- layout.Controls.Add(btnRemove);
- Load+=new EventHandler(Form1_Load);
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- _employees = new BindingList<Employee>();
- for (int i = 0; i < 10; i++)
- {
- _employees.Add(new Employee() { Id = i, Name = "Employee " + i.ToString() });
- }
- lstEmployees.DisplayMember = "Name";
- lstEmployees.DataSource = _employees;
- txtId.DataBindings.Add("Text", _employees, "Id");
- txtName.DataBindings.Add("Text", _employees, "Name");
- }
- private void btnRemove_Click(object sender, EventArgs e)
- {
- Employee selectedEmployee = (Employee)lstEmployees.SelectedItem;
- if (selectedEmployee != null)
- {
- _employees.Remove(selectedEmployee);
- }
- }
- }
- }
- public class RefreshingListBox : ListBox
- {
- public new void RefreshItem(int index)
- {
- base.RefreshItem(index);
- }
- public new void RefreshItems()
- {
- base.RefreshItems();
- }
- }
- Public Class Form1
- Private datasource As New List(Of NumberInfo)
- Private bindingSource As New BindingSource
- Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
- MyBase.OnLoad(e)
- For i As Integer = 1 To 3
- Dim tempInfo As New NumberInfo()
- tempInfo.Count = i
- tempInfo.Number = i * 100
- datasource.Add(tempInfo)
- Next
- bindingSource.DataSource = datasource
- ListBox1.DataSource = bindingSource
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- For Each objItem As Object In datasource
- Dim info As NumberInfo = DirectCast(objItem, NumberInfo)
- info.Count += 1
- Next
- bindingSource.ResetBindings(False)
- End Sub
- End Class
- Public Class NumberInfo
- Public Count As Integer
- Public Number As Integer
- Public Overrides Function ToString() As String
- Return String.Format("{0}, {1}", Count, Number)
- End Function
- End Class
- public class ListBox2 : ListBox {
- public void RefreshItem2(int index) {
- RefreshItem(index);
- }
- }
- if (objLstTypes.SelectedItem != null)
- {
- PublisherTypeDescriptor objType = (PublisherTypeDescriptor)objLstTypes.SelectedItem;
- objLstTypes.Items.Remove(objType);
- objLstTypes.Items.Add(objType);
- objLstTypes.SelectedItem = objType;
- }
Add Comment
Please, Sign In to add comment