We help IT Professionals succeed at work.

Displaying data in a C# winform

the_b1ackfox
the_b1ackfox asked
on
Hello Expert developers,

Traditionally I have used the datadridview to display information from a database.  Now I have a need to display data under a title  like this:

Bob Johnson
         Invoice 1
         Invoice 2
         Meeting Notes
Brad Smith
         Blah blah
         Blah blah blah


I would like the name and the items under the name to be items I could click on and do something with (if possible) if not, what could I use to display data like this?

Fox
Comment
Watch Question

AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
A tree view ?
the_b1ackfoxTechnophile

Author

Commented:
Hello Andy, do you have a good reference on populating the tree view?
Commented:
Or you could still use a gridview.
Just put the data in a datatable or dataset. Manipulate the datasource as desired, then bind the gridview to it.
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT
Commented:
the_b1ackfoxTechnophile

Author

Commented:
Is there any other control that can do something like this?  

rick_gwu:  I have the data in a dataset, but how could you manipulate the data source for this?

Commented:
Are the data fields common to all users?

Bob Johnson
   Invoice 1
   Invoice 2
   Meeting Notes
Brad Smith
   Invoice 1
   Invoice 2
   Meeting Notes
Otis Spunkmeyer
   Invoice 1
   Invoice 2
   Meeting Notes
etc.... ?

What does your data row look like?
AndyAinscowFreelance programmer / Consultant
CERTIFIED EXPERT

Commented:
>>Is there any other control that can do something like this?  

What do you mean?  Display in a tree structure but it isn't a tree ?
You could use a gridview but it won't look like a tree.
the_b1ackfoxTechnophile

Author

Commented:
Rick, your initial comment got me thinking...   about manipulating the associated data and I found that with the right amount of manipulation you can indeed have your data in a dataview, and sort of like a tree view.  I will post an example (and no, I didn't come up with it, you guys just prompted me to ask the right questions), and split the points
the_b1ackfoxTechnophile

Author

Commented:
Here is a sample that produces the data as hoped but in a format I could stuff into a data grid:

select
'Bob' c1, 'Barker' c2, ' Blah' c3, ' blah' c4, ' blah' c5, ' blah' c6 into #tmp
insert into #tmp
values ('Bob','Barker','Blah1','blah1','blah1','blah1')
insert into #tmp
values ('Bob','Barker','Blah2','blah2','blah2','blah2')

insert into #tmp
values ('Rob','Barker','Blah1','blah1','blah1','blah1')
insert into #tmp
values ('Rob','Barker','Blah2','blah2','blah2','blah2')


-- get results
-- column rn needed for ordering your results

WITH t_CTE (rn, c1, c2, uname, cnt)
AS
-- Define the CTE query.
(
    SELECT rOW_NUMBER() OVER(ORDER BY c1, c2), c1, c2,c1+' '+ c2 uname , COUNT(*) as cnt
    FROM #tmp
   group by c1, c2,c1+' '+ c2
)


SELECT '             ' name ,c3+','+c4+','+c5 blah
,  (ROW_NUMBER() OVER(ORDER BY t.uname)) + power(100,rn) AS rn
FROM #tmp u join t_CTE t on u.c1=t.c1 and u.c2=t.c2
union all
select  uname,''
,  power(100,rn)  from t_CTE t
order by rn

Explore More ContentExplore courses, solutions, and other research materials related to this topic.