Posts

Showing posts with the label BindingSource

Donate

AllowUsersToAddRows In DataGridView Not Working If DataSource is List<T>

Greetings! Going back to a previous project of mine, I found out that some DataGridView control's DataSource where set using List<T> and as a result, prevented the users to add new data to the DataGridView. private void List() { List<Item> list = new List<Item>(); for ( int i = 0; i < 100; i++) { list.Add( new Item() { ID = i, Name = String.Format( "{0}:{1}" , "Test" , i.ToString()) }); } DataGridView1.DataSource = list; } The common solution is to use DataTable as the DataSource but if we want to use a List type object, we could use BindingList<T> or BindingSource. Both of these have AllowNew property which indicates that you can add items to the list using the AddNew() method. It is stated in DataGridView.AllowUsersToAddRows that " If the DataGridView is bound to data, the user is allowed to add rows if both this property and the data source's IBindingList.AllowNew property are set to true. ".Well, Lis

DataGridview Paging Using BindingSource And BindingNavigator In VB.NET

Image
Hi, In reference to the previous post on DataGridView paging using C# Datagridview paging using BindingSource in C# , I developed a Visual Basic.NET version for VB.NET Developers. Main Form Class: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 Option Infer On Imports System.Configuration Imports System.ComponentModel Imports MySql Imports MySql.Data Imports MySql.Data.MySqlClient Public Class FBinding Public Property TotalRecords() As Integer Public Const PageSize = 10 Private sourceData As New List( Of String ) Private dtSource As New DataTable Dim page As New PageOffsetList() Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initiali

DataGridview Paging Using BindingSource And BindingNavigator In C#

Image
Hello, VB.NET Version Here: DataGridview Paging Using BindingSource And BindingNavigator In VB.NET Here's a simple way to integrate paging in Datagridview using BindingNavigator and BindingSource. The original source can be found here: How can we do paging in datagridview in winform . I made some modifications to simulate loading of thousands of records from a database. Main Form Class: public partial class FBinding : Form { public static int totalRecords { get ; set ; } public const int pageSize = 10; private List< string > sourceData = new List< string >(); private DataTable dtSource = new DataTable(); public FBinding() { InitializeComponent(); bindingNav.BindingSource = bindingWebsite; bindingWebsite.CurrentChanged += new EventHandler(bindingWebsite_CurrentChanged); SetSource(); bindingWebsite.DataSource = new PageOffsetList(); } void bindingWebsite_CurrentChanged( object sender, EventAr

Donate