473,761 Members | 3,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView only displaying data if cell selected

Hi all,

I am experiencing some odd behaviour with a DataGridView.

The DataGridView is bound to a DataTable, which is populated with data
from a csv file.

The column Headings appear fine, but the data only appears if I select a
cell otherwise the DGV look empty apart from the selected cell.

I am Programmaticall y binding the DGV to the DataTable after I have
populated the table.

if I select each individual cell then the correct data appears, but as
soon as I select another the new cell data appears and the old disappears.

I am doing a DGV.Refresh() after setting DataSource Property but this is
not helping me.

Can somebody please give me some idea what is happening here

I am using C# Express 2005 SP1 on WinXP SP2 with all latest updates

Regards
RichT

Feb 23 '07 #1
3 2295
Where is your code?

chanmm

"RichT" <ri*****@btinte rnet.DOTCOMwrot e in message
news:er******** **@news.freedom 2surf.net...
Hi all,

I am experiencing some odd behaviour with a DataGridView.

The DataGridView is bound to a DataTable, which is populated with data
from a csv file.

The column Headings appear fine, but the data only appears if I select a
cell otherwise the DGV look empty apart from the selected cell.

I am Programmaticall y binding the DGV to the DataTable after I have
populated the table.

if I select each individual cell then the correct data appears, but as
soon as I select another the new cell data appears and the old disappears.

I am doing a DGV.Refresh() after setting DataSource Property but this is
not helping me.

Can somebody please give me some idea what is happening here

I am using C# Express 2005 SP1 on WinXP SP2 with all latest updates

Regards
RichT

Feb 24 '07 #2
Ming Man Chan wrote:
Where is your code?

chanmm
The data is definitely loaded in the data table as I have looped through
this and printed the contents.

Once the function completes it appears that the grid has only loaded one
item, as only the top leftmost cell displays data, however if I select a
different cell, then data appears in new cell but old cell appears blank

code below

any ideas please?

fileData.Data is a List of string[];
public partial class MainForm: Form
{
DataTable tableData = new DataTable();
DataRow newDataRow;
DataColumn newDataColumn;
}

private void PopulateGrid()
{
foreach ( string header in fileData.Data[ 0 ] )
{
if ( !( tableData.Colum ns.Contains( header ) ) )
{

DataColumn newDataCol =
tableData.Colum ns.Add(header, typeof(String)) ;
newDataCol.Allo wDBNull = true;
newDataCol.Uniq ue = false;
}
else
{
DataColumn newDataCol =
tableData.Colum ns.Add("Duplica te_" + header, typeof(String)) ;
newDataCol.Allo wDBNull = true;
newDataCol.Uniq ue = false;
}
}

for ( int j = 1; j < fileData.Data.C ount; ++j )
{
newDataRow = tableData.NewRo w();
for ( int i = 0; i < fileData.Data[ j ].Length; ++i )
{
newDataRow[ i ] = fileData.Data[ j ][ i ];
}

tableData.Rows. Add( newDataRow );
}
dataGridViewOri ginal.DataSourc e = tableData;
dataGridViewOri ginal.Refresh() ;
}
Feb 26 '07 #3
Ming Man Chan wrote:
Where is your code?

chanmm
The data is definitely loaded in the data table as I have looped through
this and printed the contents.

Once the function completes it appears that the grid has only loaded one
item, as only the top leftmost cell displays data, however if I select a
different cell, then data appears in new cell but old cell appears blank

code below

any ideas please?

fileData.Data is a List of string[];
public partial class MainForm: Form
{
DataTable tableData = new DataTable();
DataRow newDataRow;
DataColumn newDataColumn;
}

private void PopulateGrid()
{
foreach ( string header in fileData.Data[ 0 ] )
{
if ( !( tableData.Colum ns.Contains( header ) ) )
{

DataColumn newDataCol = tableData.Colum ns.Add(header,
typeof(String)) ;
newDataCol.Allo wDBNull = true;
newDataCol.Uniq ue = false;
}
else
{
DataColumn newDataCol = tableData.Colum ns.Add("Duplica te_"
+ header, typeof(String)) ;
newDataCol.Allo wDBNull = true;
newDataCol.Uniq ue = false;
}
}

for ( int j = 1; j < fileData.Data.C ount; ++j )
{
newDataRow = tableData.NewRo w();
for ( int i = 0; i < fileData.Data[ j ].Length; ++i )
{
newDataRow[ i ] = fileData.Data[ j ][ i ];
}

tableData.Rows. Add( newDataRow );
}
dataGridViewOri ginal.DataSourc e = tableData;
dataGridViewOri ginal.Refresh() ;
}
Feb 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2410
by: Bharathi Kumar | last post by:
Hi, Iam working on a window application using vb.net 2005. There is a control "DataGridView" in vs 2005 instead of data grid control. After binding the datagridview, When we click on any cell to modify the data (or anything) the entire cell will be selected.
1
4163
by: Riley | last post by:
Need some help. I am using datagridview in 2005 with C#. I am calling a web service and filling the datagridview with the data returned. This all works fine. Next step is to take a value from one of the cells in the datagridview and return it back with some other values in an object for another webservice call. The problem is I dont know how to access a cell in a datagridview to do this. Im pretty sure you have to do it thru the binding...
0
2174
by: joey.powell | last post by:
I have a Windows Forms application where I need to be able to drag and then drop onto a datagridview control. I already have the code necessary to make the drag part work. I am having problems, however, when I attempt to drop onto a cell in the datagridview. So far I have done the following with the datagridview control... 1. I set "AllowDrop" to true. 2. In the DragEnter event I put this...
3
4654
by: Daniel Manes | last post by:
I need a strategy to debug this situation... I can't put all the code involved, but here are some of the critical lines with comments: ------------------------- Private _parentDataCell As DataGridViewCell 'declare private field _parentDataCell = _parentDataGrid.Rows(rowIndex).Cells(columnIndex) 'set to a specific cell Debug.Print(_parentDataCell.DataGridView.ToString) 'prints:
130
6629
by: Daniel Manes | last post by:
I'm baffled. I have a column in a SQL Server Express database called "Longitude," which is a float. When I view the table in a DataGridView, some of the numbers, which only have two decimal places in the database show up with *15* decimal places and are ever so slightly off (in the example in the subject line, by about 2E-15). I'm not doing any operations on this column. It's just running a stored procedure which performs a pretty basic...
3
6330
by: =?Utf-8?B?Sm9obiBCdW5keQ==?= | last post by:
New to databinding in vs2005, I always did it manually in 2003. I have no problem loading comboboxes, and a change in that combobox changes the data in the textboxes but I can not figure out a way to get the data in a datagridview to change. For example 2 columns are ID and amount_paid, the datagridview loads on form load with all ID's and amounts. How do I get it to only bring back the selected ID. Sounds like I may need to change the SQL...
7
15658
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 there an equivalent property for the DataGridView? I have searched, but have not found one. I would like the user to be able to see all the columns of the table on one screen - thus eliminating the need to use the horizontal scroll bar to view...
12
13646
by: cj | last post by:
When viewing a datatable in a datagridview one of the columns in it is a "note" field which can be quite long. I would like to have the note field of the currently selected row of the datagrid display in a textbox below the datgridview. I currently have it fixed so if you click on a row the note field from that row is put in the textbox. I'd like this to be automatic as they move through rows. Also the note field is one of two fields...
1
3379
by: TG | last post by:
Hi! I have an application in which I have some checkboxes and depending which ones are checked those columns will show in the datagridview from sql server or no. After that I have 2 buttons: 1) export to excel button exports the visible columns from the datagridview to excel (this works fine)
0
9948
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9902
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8770
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7327
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5364
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3866
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.