473,412 Members | 2,239 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

DataGridView

Hi there,
I have a DataGridView on a Windows Form. The form load event looks like this
private void Form1_Load(object sender, EventArgs e)
{
MyCollection mycoll=new MyCollection();
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView1.AutoGenerateColumns = false;
BindingSource bs = new BindingSource();
bs.DataSource = mycoll.GetRecords(1);
dataGridView1.DataSource = bs;
}


Here, data from a Collection object (MyCollection) is being stored in a BindingSource. From the BindingSource it is than passed on to the DataGridView. On debugging, all three (the collection object, the BindingSource and the DataGridView) show that they have the values. But after running the application, the DataGridView doesn't display the values.
Kindly tell me a solution for this.
P.S.: GetRecords() is my function which returns a collection. dataGridView1 on the form is totally blank with no columns and no rows.
Thanks in advance
Dec 27 '07 #1
5 1369
mzmishra
390 Expert 256MB
I think you have missed the DataBind() method
Dec 27 '07 #2
I think you have missed the DataBind() method


DataGridView control doesn't have a DataBind() method.
Dec 27 '07 #3
mzmishra
390 Expert 256MB
oh sorry for this.
I though it is a datagrid.
Dec 27 '07 #4
oh sorry for this.
I though it is a datagrid.

I hope this work


Expand|Select|Wrap|Line Numbers
  1. private void Form1_Load(object sender, EventArgs e)
  2. {
  3. MyCollection mycoll=new MyCollection();
  4. dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  5. dataGridView1.AutoGenerateColumns = false;
  6. BindingSource bs = new BindingSource();
  7. bs.DataSource = mycoll.GetRecords(1);
  8.  
  9. DataSet Ds;
  10. Ds = new DataSet();
  11.  
  12. DataTable DT;
  13. DT = new DataTable();
  14.  
  15. Ds.Tables.Add(DT);
  16. Ds.Load(bs, LoadOption.PreserveChanges, Ds.Tables[0]);
  17.  
  18.  
  19. dataGridView1.DataSource = Ds.Tables[0];
  20. }
Dec 27 '07 #5
Hi vksingh24,
thanks for the help.

I tried it out by your way. There were three errors at compile time on the following line:

Ds.Load(bs, LoadOption.PreserveChanges, Ds.Tables[0]);

Errors:
1. The best overloaded method match for 'System.Data.DataSet.Load(System.Data.IDataReader, System.Data.LoadOption, System.Data.FillErrorEventHandler, params System.Data.DataTable[])' has some invalid arguments.

2. Argument '1': cannot convert from 'object' to 'System.Data.IDataReader'.

3. Argument '3': cannot convert from 'System.Data.DataTable' to 'System.Data.FillErrorEventHandler'.
Dec 28 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: DraguVaso | last post by:
Hi, I'm using the DataGridView in VB.NET 2.0. The DataSource is a Generic List of a custom class0: lstMyPersonnes = New List(Of clsPersonne). When I add a new clsPersonne to lstMyPersonnes,...
6
by: dbuchanan | last post by:
Hello, Is this a bug? Is there some kind of work around? I want to add default values for a few columns in my datagridview I found the "DefaultValuesNeeded" event for the datagridview I...
10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
2
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
0
by: jeastman - Hotmail | last post by:
Hello world Excuse, not to be written English and it helps me with a translator. I am new programming in C#. I made a control inheriting the DataGridView to be able to add controls done by...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.