Problem with DataView.Add() : the new item isn't shown/focused inthe ListBox

  • Thread starter Thread starter Lorenz Kahl
  • Start date Start date
L

Lorenz Kahl

Hi,

I have a real serious problem I can't figure out myself. Here's the
pretty plain scenario:

I have a DataSet with one table. I created a DataView on that table.
I have a Listbox bound to the DataView to select items to display and
edit in a couple of TextBoxes. So far everything is fine.

Now I'd like to add a button that allows the user to add an item to the
list. In the event handler of the button click I call the Add()-method
of the DataView. Unfortunately nothing happens to the UI visually. The
selected item in the list stays unchanged. I can select the newly added
'empty' item manually at the bottom of the list though. But the
TextBoxes still show all the details of the last selected 'real' item.

When I press the add-button I would like to have the newly added item
(row) selected in the ListBox automatically and all the TextBoxes
blanked out. That's exactly the result that I got when I dropped the
DataView and bound all controls to the DataTable of the DataSet
directly. I just don't understand it.
But I need to use a DataView so I will be able to filter the data that
will be displayed. Oh, I might mention that there is NO RowFilter set on
the DataView (yet) that might prevent the newly added row from showing.

Can somebody please help me?! I would really appreciate it.

PS: I also already tried to use the Add()-method of the underlying
CurrencyManager. It's still the same :-(


Best regards,
Lorenz
 
Hi,

finally I figured this one out ;-)

It's not the DataView that's the bad guy - it really was the
DateTimePicker again.

Besides all the TextBox-controls I also had two DateTimePickers on my
form. The underlying DataTable-fields were declared as type dateTime -
that's how they were generated since the database also has dateTime types.

IMHO it's impossible to set a default date for dateTime-Fields in the
DataSet xsd-schema. The problem is, that when I added a new row, the
fields for the dates were initially NULL and that's what the
DateTimePicker can't cope with. And that's the only reason why the newly
added row wasn't focused. And that's the only reason why all the other
TextBoxes didn't refresh their values.

To express it mildly: I think the implementation of the
DateTimePicker-control is slightly 'sub-optimal'. In order to display an
'empty' DateTimePicker I even read about another guy using the
graphics-library to draw a blank box over the control, until the user
selected a value. Tis, tis, tis...

To get it to work for me, I changed the datatype of the DataSet to
String and put some stupid default date in - like "01.01.2004". Now when
I add a new row I change the value of the DateTimePickers immediately
and set them to DateTime.Now. This works in my case fortunately.

Best regards,
Lorenz
 
Back
Top