all groups > dotnet windows forms > september 2003 >
You're in the

dotnet windows forms

group:

DATAGRID PROBLEMS


DATAGRID PROBLEMS Kenneth Clive
9/30/2003 5:03:25 PM
dotnet windows forms:
I've had a problem with one of the DataGrids in my
program that's been a thorn in my side for FIVE WEEKS!
Whenever I click on a cell in the DataGrid to edit or
update a record, the cell goes blank. I can edit, but I
CAN'T SEE WHAT I'M DOING! I checked the SelectionColor
properties: the back color and front color were fine. I
don't know if this has to do with it. I get an error
message when I try to write updates back to the original
database (database was created in Access 2000):

An unhandled exception of
type 'System.Data.OleDb.OleDbException' occurred in
system.data.dll

What's the problem, and how do I fix it?

Regards,

Re: DATAGRID PROBLEMS Dmitriy Lapshin [C# / .NET MVP]
10/1/2003 9:54:14 AM
Hi Kenneth,

Do you do any programmatic customizations to the DataGrid?
Do you use custom table styles and/or column styles?

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

[quoted text, click to view]
Re: DATAGRID PROBLEMS Kenneth Clive
10/2/2003 1:19:03 PM
Yes, I do. But, my code does not mess with how the grid
looks. I use a combobox so that the user can choose which
table to view and/or update.
[quoted text, click to view]
Re: DATAGRID PROBLEMS Dmitriy Lapshin [C# / .NET MVP]
10/3/2003 10:15:20 AM
I assume you re-bind the grid every time the user switches to another table
in the combobox? If this is the case, ensure you use the SetDataBinding
method to re-bind the grid to a new data source.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

[quoted text, click to view]
Re: DATAGRID PROBLEMS Kenneth Clive
10/4/2003 10:30:01 AM
Dear Dmitry,

Well, what I do with the DataGrid when the user chooses
an item in the ComboBox is to re-set the DataGrid's
DataMember property to the corresponding table. So, along
with this property setting, I should use the
SetDataBinding method.

Also, I only have one DataSource, which is my lone
dataset, DsDatabase1. Should I just do this, even though
it will stay the same?:

..SetDataBinding(DsDatabase1)

Regards,

Kenneth Clive.

[quoted text, click to view]
Re: DATAGRID PROBLEMS Dmitriy Lapshin [C# / .NET MVP]
10/6/2003 10:28:47 AM
Kenneth,

I beleive the SetDataBinding method has two overloads, and the one you need
accepts two arguments: the data source and the data member. The data source
will always be the same, that's right, but the data member will be different
each time the user chooses another table in the combobox.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

[quoted text, click to view]
Re: DATAGRID PROBLEMS Kenneth Clive
10/6/2003 5:23:22 PM
I need yet more help! I did exactly what you suggested,
but this error message popped up when I tested my program:

An unhandled exception of type 'System.ArgumentException'
occurred in system.windows.forms.dll

Additional information: Can't create a child list for
field Members.

This popped up everytime when I selected a table, ANY
table. Am I doing this right, Dmitriy?:

DataGrid1.SetDataBinding("DsDatabase1", cboTables.Text)

The Datasource is my dataset, and the datamember is the
current text that the combobox is displaying. Is
something wrong?

Sincerely,

Kenneth Clive.


[quoted text, click to view]
Re: DATAGRID PROBLEMS Dmitriy Lapshin [C# / .NET MVP]
10/7/2003 12:42:14 PM
The DataMember value should be equal to the corresponding DataTable's Name
property value. I assume your combo box enumerates a kind of "display"
names, and these won't do as DataMember values.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

[quoted text, click to view]
Re: DATAGRID PROBLEMS Kenneth Clive
10/7/2003 5:23:01 PM
Well, I tried your suggestion with this code:

DataGrid1.SetDataBinding("DsDatabase1",
DsDatabase1.Stocks)

But, an error came up while coding that said the second
argument's value couldn't be converted to a String, which
is what that second argument requires. Here's what I did
next:

DataGrid1.SetDataBinding("DsDatabase1",
DsDatabase1.Stocks.TableName)

That didn't work either, because I used pretty much the
same method that I used with the combobox's text
property. You said to use the corresponding DataTable's
name, but that's not a string; it's a DataTable object
type. What should I do?
[quoted text, click to view]
Re: DATAGRID PROBLEMS Dmitriy Lapshin [C# / .NET MVP]
10/8/2003 11:29:58 AM
Kenneth,

The TableName property is the one that should be passed as the DataMember.
So your binding code should look like:

DataGrid1.SetDataBinding(DsDatabase1, _
DsDatabase1.Stocks.TableName)

(assuming Stocks is a property of a typed dataset returning a DataTable
instance).

Note that the first parameter is the DataSet itself, not a string like in
the snippets you have given. That approach wouldn't work indeed.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

[quoted text, click to view]
Re: DATAGRID PROBLEMS Kenneth Clive
10/11/2003 6:23:56 PM
Well, I did what you said, but I still can't see what I
am editing in the cells of the DataGrid. I have these
lines of code in a If...Then statement:

If cboTables.Text = "Stocks" Then
DataGrid1.SetDataBinding(DsDatabase1,_
DsDatabase1.Stocks.TableName)
OleDbAdapterStocks.Fill(DsDatabase1)
Count()
End If

"Count" is a procedure I created that sets a label that
shows your position and the total number of records
("Record 1 of 32"). What is wrong?

Regards,

Kenneth Clive


[quoted text, click to view]
Re: DATAGRID PROBLEMS Dmitriy Lapshin [C# / .NET MVP]
10/13/2003 12:15:27 PM
Kenneth,

[quoted text, click to view]

You are trying to bind the grid BEFORE retrieving the data. Swap these lines
to make your code look like this:

If cboTables.Text = "Stocks" Then
OleDbAdapterStocks.Fill(DsDatabase1)
Count()
DataGrid1.SetDataBinding(DsDatabase1,_
DsDatabase1.Stocks.TableName)
End If


--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

[quoted text, click to view]
Re: DATAGRID PROBLEMS Kenneth Clive
10/15/2003 5:52:05 PM
Your method of fixing my error did work, but I still
can't see what is in the cell while I am editing the
cell's content. Whenever a cell is in focus, I cannot see
anything in the cell. When I put another cell in focus,
the first cell's contents come back, but the current
cell's content disappears. I'm connecting to an Access
2000 database (this may relate to my problem here).

Regards,

Kenneth Clive.
[quoted text, click to view]
Re: DATAGRID PROBLEMS Kenneth Clive
10/17/2003 5:24:55 PM
I tried your code, but it didn't stop that nagging
problem about the DataGrid. I still can't see what I'm
editing when a cell is in focus. I'm connected to an
Access 2000 database. I have a computer running XP Home
Edition on it (I should have Pro, but I'll get it later).
Is there a problem with the db engine, or is there a
problem with VB?

Regards,

Kenneth Clive.
[quoted text, click to view]
Re: DATAGRID PROBLEMS Dmitriy Lapshin [C# / .NET MVP]
10/20/2003 9:25:32 AM
Kenneth,

[quoted text, click to view]

Both are unlikely. You could check the ForeColor and BackColor property
values on text boxes hosted by the DataGridColumnStyle(s). You can access
these checkboxes through the DataGridColumnStyle.TextBox property. I'm
afraid I wouldn't be able to suggest anything else without an ability to
play with the program itself.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

[quoted text, click to view]
AddThis Social Bookmark Button