.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Binding DataGridView --- DataSet or Collection

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :Windows Application
This is my experiences. I can bind the DataGridView using DataSet and Collection. 1st expericence, If using DataSet, my DataGridView have an empty row at the last row (have to set AllowUserToAddRows Property to False). If using Collection, my DataGridView do not have empty row at the last row. 2nd experience, I know how to rebind the DataGridView using DataSet. But I dont know how to rebind the DataGridView using Collection. My collection as follow, private Collection<MasterAgentCompany> myDGV = new Collection<MasterAgentCompany>(); private BindingSource bindingSource = new BindingSource(); dgv1.DataSource = bindingSource; bindingSource.DataSource = myDGV; dgv1.Refresh(); /*THIS CODE IS OK ON 1ST TIME LOAD*/ /*IF I'M CALLING THIS CODE AGAIN, MY DATAGRIDVIEW NOT REFRESH THE NEW RECORD*/ I'm looking the right technique to rebind DataGridView using Collection I'm stuck. Really looking for help

View Complete Post

More Related Resource Links

Columns collection of a DataGridView within a UserControl won't serialize to designer

First of all, I've found this issue on connect which describes my problems exactly, however, I've been able to find a workaround but I don't find it acceptable so I appeal to you for an idea of how to resolve this as cleanly as possible. What I've done is, I've applied a custom designer to my UserControl like so [Designer(typeof(CustomControlDesigner))]public partial class DataGridViewTag : UserControl, ISupportInitialize In the CustomControlDesigner I don't do much at this point, I set selection rules and add a few DesignerVerbs. The important thing is, I also EnableDesignMode for the DataGridView in my UserControl. Then, I expose DataGridView's DataSource and Columns collection like this: [Editor(typeof(CollectionEditor), typeof(UITypeEditor))][Category("Grid")][DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]public DataGridViewColumnCollection Columns{    get { return dgvList.Columns; } set { dgvList.Columns.Clear(); foreach (DataGridViewColumn col in value) dgvList.Columns.Add(col); }} [AttributeProvider(typeof(IListSource))] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] [Category("Grid")] public object DataSource{ get { return dgvList.DataSource;&nbs

autocomplete combobox/textbox binding to dataset


Hi All.

I found sample http://www.codeproject.com/KB/WPF/WPFAutoCompleteTextbox.aspxAutoComplete ComboBox where data is hardcoded in the code. I would like to use AutoComplete ComboBox binded to dataset. I don't have a problem binding data to ComboBox but I have problem if need that combobox autocomplete and filtered listbox. That is bit of code which I found

  Public Sub New()

    textBox1.AddItem(New AutoCompleteEntry("Toyota Camry", "Toyota Camry", "camry", "car", "sedan"))
    textBox1.AddItem(New AutoCompleteEntry("Toyota Corolla", "Toyota Corolla", 

Binding to an observable collection in a custom WPF control


Hi everyone,

I'll first explain a bit what I'm doing so that the code paste will make a bit more sense. I'm creating a circular menu control for Microsoft Surface (this question is far from Surface specific though, but otherwise this type of control wouldn't make sense :) ), it has some 'pieces' which are all buttons. I've created a 'Menu' control which contains the menu items, I made a custom control for these items (so I could add them to the menu within XAML), and I made a Button control which actually does the drawing of the path etc. I've done this in this specific way because the angle of the button's path will depend on the number of pieces within the menu. Anyway the above all works fine and dandy and I'm happy with the result. However now I'm trying to get all of this to work.

What I want to do is to use MVVM in my application and bind the MenuItems to a command in my ViewModel. So I have an AdminToolbox which is a view containing the menu and there's an AdminToolboxViewModel which is the ViewModel with the command and the items that I'd need to bind to my menu to create the menu items.

Some code pastes:



Insert data to ms access from datagridview using dataset


please give me sample code for insert data to MS ACCESS  from grid view using dataset

Binding a TreeView to a collection of objects



I want to achieve this:


through data binding. That is, I've got this collection of objects of the same class (currently stored in a ArrayList), and I want to display them in a treeview, so that when you expand them you can see the values of their attributes.

Is it possible to do it via DataBinding?





Problem binding a collection to a view model on POST when manipulating the DOM with javascript.


Hi, i'm currently working on a strongly typed view and i'm binding a collection to a table like this:


for (int i = 0; i < Model.Cars.Count; i++)





<%= Html.Hidden(String.Format("Cars[{0}].Id", i),




<%= HtmlTextBox(String.Format("Cars[{0}].CarModel", i),



Binding Source and DataGridView not talking

I have on a form a bindingsource, a dataviewgrid, a bindingsourcenavigator, a tableadaptor and a few textboxes linked to the


I need to be able to change the data using a query.

I have the following code which is generated when i select inactive or active for example:

Dim connString As

Binding a Dataset with Parent - Child



I have been tearing my hair out with this one.


I have a DataSet with two tables "Services" and "Methods" connected by a relation "FK_Service_Method.

I have populated a TreeView using the HierarchicalDataTemplate and that works fine.

Now I have two TextBoxes, one bound to ServiceName the other MethodName.

If I click on the ServiceName in the TreeView the bound ServiceName Textbox updates and the MethodName TextBox gets the first child MethodName

BUT if I click on a child MethodName I can't get the MethodName TextBox to reflect my change.

Here is the XAML



        <CollectionViewSource x:Key="ServicesDataView" Source="{Binding Path=Service}

TwoWay data binding to a specified index and property in a collection


Hello everybody,

my problem is, I can't bind to a specified item and property in a collection. The code:

    <test:ValueConverter x:Key="valueConverter" />
    <ContentPresenter x:Key="cont1" Content="{Binding Path=.[0], Mode=TwoWay}" />

WPF Treeview - Binding to a collection with different depths, and styling differently


Apologies for the long post -- Read a few threads about this, but still find it hard to implement. Basically, I have a collection of objects, defined as:

public class LibData
  public string Name { get; set; }
  ObservableCollection<LibObject> _list;
  public ObservableCollection<LibObject> List { get { return _list; } }

  public LibData(string name, LibDataType type)
    this.Name = name;
    _list = new ObservableCollection<LibObject>();

Dynamicobject collection binding on WPF DataGrid , not working ?



I am trying to bind dynamic list of items to the WPF DataGrid , but its not working .

my Dynamic list is

 // CustomDynamicObj is inherited from DynamicObject

  dynamic listItems = new List<CustomDynamicObj>();

 this.dataGrid1.DataContext = listItems;

And my XAML is

   <DataGrid AutoGenerateColumns="True" ItemsSource="{Binding}" Name="dataGrid1" VerticalAlignment="Stretch"  />

If I add columns through code in DataGrid then above code works fine , but I want to Autogenerate columns .

Any workaround for this plz ?



Binding a Collection to a ComboBox


The following is a the class, a list of which I wish to display in a WPF combo box
    public class DivisionItem

        private int _divn_ID = -1;
        private string _divn_Nm = "";
        private int _divn_Mgr = -1;

        private string _addrLn1 =&nb

Can't sort dataset - what ADO.net object should I use for binding to PathListBox.ItemsSource that w


This is the VB.NET code using the dataset:

Imports System.Data.OleDb

Public Class winLookup

  Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnClose.Click
  End Sub

  Private Sub winLookup_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
    Dim ds As New System.Data.DataSet("CustomerProperties")



Binding WPF Controls to an Entity Data Model

In this interview, programming writer, McLean Schofield, demonstrates how to bind WPF controls to an entity data model, using Visual Studio 2010 Beta 1. You can also learn more in the topic: Walkthrough: Binding WPF Controls to an Entity Data Model.

Binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Here is the code for binding the multiple drop down boxes in GridView using JQuery in ASP.NET

Custom Editing Behavior for DataGridView TextBox Columns

For various reasons I'm using a DataGridView instead of a ListView, and while configuring the DataGridView to look like a ListView wasn't much of a problem, there's one thing that got on my nerves, which is the behavior of textbox cells in edit mode: It is much too easy to leave the edit mode accidentally, simply by pressing the cursor keys at the wrong time. For example when the text caret is positioned behind the last character of the textbox cell content, and you press the right arrow key

AutoCompleteStringCollection for text box in DataGridView 2.0

I have been searching for a way to have autocomplete in a DataGridTextBox
object. There does not appear to be an obvious way to do this like you would
for a TextBox outside of a grid using the AutoCompleteCustomSource. Any
thoughts on how I can add this collection? :)
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend