We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Adding items to DataGrid in runtime

Thread ID:

Created:

Updated:

Platform:

Replies:

33651 Aug 23,2005 02:56 PM Dec 5,2005 10:20 PM Windows Forms 2
loading
Tags: FAQ
Hisham
Asked On August 23, 2005 02:56 PM

I have a system.windows.forms.form with a datagrid in it. in the load method i bind a dataTable into it. and i have a method that in runtime adds some items to the dataTable after an event. i did the following: DataTable dataTable =(DataTable)dataGrid.dataSourse; DataRow dataRow = dataTable.newRow(); dataRow[0] = "some string"; dataRow[1] = "another string"; dataTable.Rows.Add(dataRow); it works, but when there are more than 10 items (the max display without a scrollBar), the scrollBar is added. sometimes it''s stuck, and if not, when adding a new item there are two scrollBars, and other freak things. When adding items "slowly" it doesn''t always do that, it happens when adding 4-5 items one after another. Thanks in advance, Hisham

Hisham
Replied On August 24, 2005 03:10 AM

I got the solution (and i feel very stupid). The dataGrid updates came from different threads, that''s the reason for the problem. I solved it using BeginInvoke. Thanks, Hisham >I have a system.windows.forms.form with a datagrid in it. in the load method i bind a dataTable into it. >and i have a method that in runtime adds some items to the dataTable after an event. i did the following: > >DataTable dataTable =(DataTable)dataGrid.dataSourse; >DataRow dataRow = dataTable.newRow(); >dataRow[0] = "some string"; >dataRow[1] = "another string"; >dataTable.Rows.Add(dataRow); > >it works, but when there are more than 10 items (the max display without a scrollBar), the scrollBar is added. >sometimes it''s stuck, and if not, when adding a new item there are two scrollBars, and other freak things. >When adding items "slowly" it doesn''t always do that, it happens when adding 4-5 items one after another. > > >Thanks in advance, >Hisham >

Pet
Replied On December 5, 2005 10:20 PM

Hi, I am facing similar problme. when i bind the datatable to datagrid i am getting nullreferrence error because of multi threading. How you implement BeginInvoke? can you provide me sample for implementing BeginInvoke in DataTable

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;