PC Review


Reply
Thread Tools Rate Thread

DataGridView only displaying data if cell selected

 
 
RichT
Guest
Posts: n/a
 
      23rd Feb 2007
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 Programmatically 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

 
Reply With Quote
 
 
 
 
Ming Man Chan
Guest
Posts: n/a
 
      24th Feb 2007
Where is your code?

chanmm

"RichT" <(E-Mail Removed)> wrote in message
news:ern1sh$uvd$(E-Mail Removed)...
> 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 Programmatically 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
>



 
Reply With Quote
 
Bloke
Guest
Posts: n/a
 
      26th Feb 2007
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.Columns.Contains( header ) ) )
{

DataColumn newDataCol =
tableData.Columns.Add(header, typeof(String));
newDataCol.AllowDBNull = true;
newDataCol.Unique = false;
}
else
{
DataColumn newDataCol =
tableData.Columns.Add("Duplicate_" + header, typeof(String));
newDataCol.AllowDBNull = true;
newDataCol.Unique = false;
}
}

for ( int j = 1; j < fileData.Data.Count; ++j )
{
newDataRow = tableData.NewRow();
for ( int i = 0; i < fileData.Data[ j ].Length; ++i )
{
newDataRow[ i ] = fileData.Data[ j ][ i ];
}

tableData.Rows.Add( newDataRow );
}
dataGridViewOriginal.DataSource = tableData;
dataGridViewOriginal.Refresh();
}
 
Reply With Quote
 
RichT
Guest
Posts: n/a
 
      26th Feb 2007
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.Columns.Contains( header ) ) )
{

DataColumn newDataCol = tableData.Columns.Add(header,
typeof(String));
newDataCol.AllowDBNull = true;
newDataCol.Unique = false;
}
else
{
DataColumn newDataCol = tableData.Columns.Add("Duplicate_"
+ header, typeof(String));
newDataCol.AllowDBNull = true;
newDataCol.Unique = false;
}
}

for ( int j = 1; j < fileData.Data.Count; ++j )
{
newDataRow = tableData.NewRow();
for ( int i = 0; i < fileData.Data[ j ].Length; ++i )
{
newDataRow[ i ] = fileData.Data[ j ][ i ];
}

tableData.Rows.Add( newDataRow );
}
dataGridViewOriginal.DataSource = tableData;
dataGridViewOriginal.Refresh();
}
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get value of first cell in selected row in DataGridView? bill Microsoft Dot NET 2 11th Nov 2010 02:35 PM
Problem getting Data of selected row of databound DataGridView =?Utf-8?B?TWFya3VzIEhvZmVy?= Microsoft C# .NET 0 26th Apr 2007 06:00 PM
Displaying data from 2 tables in one datagridview Lars E. Microsoft ADO .NET 3 25th Apr 2006 02:39 PM
A formula for displaying the cell reference of the selected cell Emlou85 via OfficeKB.com Microsoft Excel Misc 3 19th Mar 2006 03:54 PM
displaying a comment only when the cell is selected Jeff Microsoft Excel Misc 2 6th Jul 2005 09:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:48 AM.