DataBinding to a DataView -- only getting first row [repost]

B

Beverley

Hi all,

I'm having a nice little conversation with myself down under the "DataBinding to a
DataView -- only getting first row" heading. I haven't had a response from anyone other
than myself, so if you could help me out, I'd really, *really* appreciate it.

Sort description... I think my databinding is screwed up on a UserControl I've created for
a Windows form application in the 1.1 framework. I haven't been able to find any examples
that go into depth on how to do it properly.

Code snips in the other thread.

Thanks very much!
Beverley
 
G

Guest

I will have to examine the other thread later, but here is the basics.

If you are looking to bind and get repetitive answers (one for each row),
use a control like a DataList (single column), DataGrid (multiple columns
with spreadsheet type look) or Repeater (fully flexible repeat on any number
of columns).

When you use a DataView, you further filter the results you are binding. If
you filter on a specific ID, you end with one record. If the filter is set on
a field with multiple rows for that value, you should be golden.

I will look for the other thread at home (where I have a news reader client
instead of this web interface).


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
B

Beverley

Is there a repeater in Windows Forms? I've seen the one in ASP.NET but I haven't come
across one in the Windows Forms world...

(I'm essentially creating my own answer to a datagrid... one line of data per each user
control.)

Thanks...
Beverley
 
C

Cowboy \(Gregory A. Beamer\)

Sorry, no. I am so stuck on Web apps. :)

You can create background grids in code, but the first thing to check is
your data. When you add your filter to the DataView, how many records does
it show? That would be my first look.

Now, the DataView is really easy to bind to a control, but harder to loop
through. Another option is to move specific rows from a Select filter on the
DataTable (pardon my VB (test it), as it is Ad Hoc and I spend more time in
C#:

'Get a table
Dim dt As DataTable = TCE.db.TheDataSet.Personnel

'You can now move through rows and set up your ad hoc binding
Foreach DataRow dr In dt.Select("SubTabID = 1")

'Bind each row here

Next

This way you are not working with DataViewRows and its klunky kind of
looping mechanism (great for straight bind filters, however).


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside the box!
*************************************************
 
B

Beverley

Thank you, thank you! That worked. I'm actually getting DIFFERENT data in each line.
It's a miracle! :)

Your code is pretty close... your for loop was just a bit off, but I'm getting pretty good
at reading C# code even though I've never used it. Here's the corrected For line, in case
anyone else is having this sort of problem:

For Each dr As DataRow In dt.Select("SubTabID = 1")
'...
Next

It doesn't look too different from what I had before, but obviously there's some subtle
difference that really mattered.

Thanks again :)
Beverley
 

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