GridView - I've gotta be missing something...

R

Richard Carpenter

I have a simple winform with a customers combobox, a "get orders"
button and an orders grid. Due to other requirements, I have
implemented the form to allow the user to select a customer from the
combobox and click the "get orders" button to refresh the gridview with
the selected customer's orders, via a GetDataByCustomerID stored
procedure.

The underlying Orders table includes, among others, three boolean
columns and one particular datetime column, all of which are set to NOT
NULL with default values. All of these columns have valid values
specified in the table, yet when I call the stored procedure to refresh
the grid, I get validation errors for those four columns and their data
does not display. The other columns display just fine.

As I mentioned, I'm getting this data from a stored procedure. The
stored procedure *does* return the values for those four columns. The
gridview for some reason sees those columns as having null values or
something.

I have completely deleted the form and recreated it. I have completely
deleted the dataset and recreated it. Neither had any effect. Each time
I redesigned it, the problem was present. Does the gridview have issues
with required values? Even if it did, shouldn't using a stored
procedure get around that?

I'm running out of things to try here. Any advice would be much
appreciated.

Rich
 
D

Dave Sexton

Hi Richard,

I assume you are referring to the DataGridView control?
gridview for some reason sees those columns as having null values or
something.

Check your in-memory DataSet after binding to verify that there is actually data in the appropriate rows/columns by setting a break
point in code, attaching a debugger and viewing the object in a watch window.
I have completely deleted the form and recreated it. I have completely
deleted the dataset and recreated it. Neither had any effect. Each time
I redesigned it, the problem was present.

I suspect that your problem might lie in your data access code. See first if the DataTable to which your DataGridView is bound
contains the appropriate data after binding as I mentioned above.
Does the gridview have issues
with required values?

Not that I'm aware of. Binding to Boolean and DateTime columns with AllowDBNull set to false has always worked in my experience
even when the DataGridView implies the columns from the schema of the data.
Even if it did, shouldn't using a stored
procedure get around that?

No. How the data gets into a DataTable has nothing to do with how the DataGridView handles reading and displaying the data. The
key here is to make sure the data, in memory, is what you expect. If it's not then go from there.
 
R

Richard Carpenter

Thanks, Dave. I'll look into that, and yes, it is the DataGridView
control that I am using.

Additionally, and forgive me for the basic question, as I am still
fairly new to ADO.Net, but I have tried accessing the data in my
DataTable before and had little luck. The object model still confounds
me to some extent. Should I drill down into the actual DataTable object
to view the data, or go through the BindingSource? If the DataTable, I
assume it starts at DataSet.DataTable...?

Also, and you can save me another thread here, when referencing that
data, how can I determine which row is current as seleted in that
DataGridView? My assumption was to look into the BindingSource object,
but I have similar questions there as with the DataTable.

Thanks for your time.
Rich
 
D

Dave Sexton

Hi Rich,
Additionally, and forgive me for the basic question, as I am still
fairly new to ADO.Net, but I have tried accessing the data in my
DataTable before and had little luck.

You are forgiven!
The object model still confounds
me to some extent. Should I drill down into the actual DataTable object
to view the data, or go through the BindingSource? If the DataTable, I
assume it starts at DataSet.DataTable...?

Here's an MSDN article that should clear up the large majority of your questions
(Pay attention in particular to the section on strong-typing DataSets if it's unfamiliar to you):

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/daag.asp
Also, and you can save me another thread here, when referencing that
data, how can I determine which row is current as seleted in that
DataGridView? My assumption was to look into the BindingSource object,
but I have similar questions there as with the DataTable.

Using the BindingSource is one way. dataGridView1.SelectedRows[index].DataBoundItem is another way that works regardless of the
Type of the binding source.

In VS.NET 2005 exporing your in-memory data is easy. Set a break point in code sometime you have bound the DataGridView to its data
source. Run the app in debug mode (F5) and when the application breaks into the debugger at your break point open a watch window
(Debug --> Windows --> Watch --> Watch 1). In the watch window enter the name of your DataSet variable on one of the lines. You'll
see a magnifying glass icon under the "Value" column right after {System.Data.DataSet}. This is a DataSet "Visualizer".
Visualizers are new to VS.NET 2005. Click the icon and you'll see a Form open that displays the contents of your DataSet.

For debugging I would try to minimize the amount of data you bring down from the server so your DataSet isn't completely bloated.
Try to repro the problem with only one DataRow if possible. You shouldn't have to worry about what row is selected or visible in
the display. It will be obvious if the data in the DataGridView is the same as the data in your DataRow.

- Dave Sexton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top