Q: How to add Head/Detail in a DataGridView.

  • Thread starter Thread starter Martin Arvidsson \(Visual Systems AB\)
  • Start date Start date
M

Martin Arvidsson \(Visual Systems AB\)

Hi!

I have seen some screen shots where they have a DataGridView with company
and to that row there is a plus sign to click. When they do, the contacts
for that company is presented.

I cant find the trick to do that.

Any idea what to look for?

Regards
Martin
 
The infragistics grid does this. The build in one doesnt as far as I know. I
havent tried will relation ships in a data set.

Ciaran O'Donnell
 
Hmmm.

The strangest thing is that i saw an example of this in a book for a while a
go and it didn't look at all at the component, so i think it's possible,
just dont know how :)

And i cant find the darn book.

Regards
Martin
 
It's not a trick, I think that implementation is just using the
built-in functionality of the datagrid.

I'm not where I can reference my book or look at my code, but here's
kinda how it goes generally...

When you look at the HTML of the datagrid, There is a <itemTemplate>
... </itemTemplate> inside of which is your layout for the data you
want to view - think of this as the "view mode". In this template
somewhere is a button (that you put there), in this case it looks like
a plus sign.

Datagrid has a property (I forget the exact name!) where you can tell
it what button will make the datagrid enter the "edit mode."

There is an <editTemplate> ... </editTemplate> inside of which is the
layout for the data for the "edit Mode". As "standard equipment"
datagrid defines "cancel" and "update" functions for the editTemplate.
These functions are triggered by buttons of course. Datagrid knows the
name of the functions, you have to write the code; and you supply the
buttons and must give them specific ID's so datagrid knows which button
does what.

To elaborate some more, the "view mode" can be showing any data, but
the idea is that the data is not in editable textboxes, etc. it's just
viewable. Clicking the "Edit" button changes to the "edit view" for
that record only - this is "standard functionality" of the datagrid -
and this view can be any data we want to show, and it should be in
editable textboxes, checkboxes, dropdown lists, etc. When we click the
"update" button, it executes the update-your-database code you've
written in the code-behind page. The datagrid provides properties and
eventhandler method names so you can 'wire up' your buttons and write
the code to handle your specific data.

I highly recommend this book:
http://www.amazon.com/ASP-NET-Data-...ef=sr_1_1/103-9895769-6253438?ie=UTF8&s=books

This


This book's author has also written extensive articles about datagrids
on www.4guysfromrolla.com

Good Luck!
 

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

Back
Top