deriving DataGridTextBoxColumn - behaviour on new rows

K

k992637

Hello

I have derived a class from DataGridTextBoxColumn and am getting some
behaviour which I do not understand and I would like to know where I am
going wrong.

The problem is like this. I have a datagrid, lets say with four
columns. Two columns have my derived style and two have the default
DataGridTextBoxColumn. When you make changes to the datagrid there is
a button to press to validate and then send the changes back to the
database to be written. The problem comes when you click in the "new
row" at the bottom of a datagrid (the blank row with the star in the
header). If you click into and then straight off the default
DataGridTextBoxColumn in the new row, the UI indicates that no new row
has been created, and if you then save the changes, no new rows are
added to the database. However when you click on and then away from
the derived class, the UI performs in the same way - it appears as if
there are no new rows added, but when you click save changes you get a
new row written to the database - with all the row default values.
This implies that the row was created in the underlying DataTable, but
that fact was not reflected in the UI of the datagrid. For reasons
that I shall not go into this is a big problem for my application.

What I would really like to know is what I need to do to get my derived
column style to behave in the same way in this situation as the
DataGridTextBoxColumn. I.e. click on and away - the UI implies that no
row has been created and that is in fact the case when writing changes
to the database.

Thanks in advance for any light that can be shed on this issue! I've
been reading lots of articles on MSDN but none that I have found seems
to cover this situation!

Best Regards
David Smith
 
G

Guest

It seems that the problem might be caused becuase you try to relate to the
current row in your custom column pre editing events. you should check your
constructor and some other code you handle there. You can check before you
update your datatable to the database if there are rows not showing in the
grid and delete them, but i would not recommend such an action. You can try
to post your customized class here so I can have a look and see if i notice
some could that could cause this problem.
 
K

k992637

Thank you Guybar - your response has pushed me in the right direction
and I have found the problem.

The edit method of the class is called twice when you click on a cell -
discovered that the second time was the problem on the following line
of code:

source.Position = rowNum;

That was what was forcing the line to be added to the datatable.
Anyway, I could see no reason why I had that piece of logic in my code
so I decided to comment it out and see what happens. The result was a
success! I will have to test more thoroughly to make sure that things
are as they should be but for the time being I think the problem is
solved.

Thanks
David Smith
 

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