DataGridView: How to allow single row to span multiple lines?

G

Guest

Hi All :)

I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView.
True DBGrid has a MultipleLines property that controls whether individual
records span multiple lines. Is there an equivalent property for the
DataGridView? I have searched, but have not found one.

I would like the user to be able to see all the columns of the table on one
screen - thus eliminating the need to use the horizontal scroll bar to view
columns that extend to the right and do not fit within the screen's view.

I am not interested in wrapping the cell text within the cell to allow the
column to have a shorter width.

If there is no such property for the DataGridView, does anyone have any
suggestions as to how to accomplish the above programmatically?

Thanks in advance for any assistance!
 
G

Guest

One thing you could do is to use multiple datagridviews. If your table
contains, say 100 rows and the form can only display 20 columns you could add
5 tables to your datasource tab (in the design view - these would be
persistent tables in the application - unless you prefer to create the tables
on the fly - I think it is just easier to create the tables in the
datasources tab - next to the solution explorer tab) then you could add an
additional form with 5 datagridview that would use each of these 5 tables
which would contain only 20 column a piece from the original table. You
could populate and clear the table as the user moves from record to record.
I will wager that something like this was going on under the hood of your
datagridPro 8.0.

The datagridview is very flexible, you can hide row headers if you don't
want to display them in the additional datagridviews, so it would look like
one continuous row.

Rich
 
G

Guest

Hi Rich,

Thank you very much for the suggestion. I would like to keep all my data
within one table. I have row validation that occurs and I think the code
involved with managing multiple tables would not be worth the benefit of
being able to display all the columns within one screen. Do you know if
there is a way to have, for example, a row that spans 3 lines where cols 0-3
are on line 1, cols 4-6 are on line 2, and cols 7-9 are on line 3? There
would be multiple rows displayed within the grid. Thanks again for your help!
 
G

Guest

Hello again,

The thing about VB2005 is that you have to write your own code, but - now
you have all the tools you need to be able to do this. With VB6 you could
not perform operations that required OOP. Now you have that. As for your
tables, you can stil use your primary table with row validation and so on.
What I am suggesting is that you pull each row from the main table into the
temp tables and display that. The original row still resides in the main
table. You clear the temp tables for each row you want to display. This is
not very resource intensive. The only catch is that you have to write a
little bit of code.

Regards,
Rich
 
G

Guest

Hi Rich,

Thanks for all your help so far :) I would like to attempt what you are
suggesting. However, I think I am not completely clear as to how to attempt
this.

I am guessing that my original query would retrieve all columns from the
table into a datatable (via an adapter) to be used as the datasource for a
bindingsource that will be used as the datasource for the dataviewgrid.

Am I using the main datagridview to populate the other 'few cols'
datagridviews or do I use the bindingsource to populate the other
datagridviews?

Also, for the row validation, etc... when the user moves from record to
record, how do I get the values the user updates to the temp grids to the
main grids?

One last question, how do I display multiple records (each made up of
multiple lines from each sub-grid) on the grid displayed to the user?

I would be very appreciative if you could write a few lines of code that
shows the basics on how to implement your suggestion.

Thank you again for all your help!
 
G

Guest

One last question,

How would I go about showing all the column headers at the top of the "grid"
for all "five" datagridviews?

Thanks again!
 
G

Guest

And one more :)

How would I be able to determine how many records to move forward/backward
when the user clicks on the vertical scrollbar - whether s/he clicks on the
up/down arrow (for one record) or in the middle of the scrollbar (for one
"screen" up or down) or by dragging the scrollbar (multiple records - how to
determine how many need to be scrolled) up or down?

Thanks again!
 
G

Guest

Good morning,

Generally, a datagridview is used for displaying detail data, and it sounds
like your records are the detail data - but you want to display each row sort
of wrapped around, so to speak. Here is another idea. On the primary form
you have the main datagridview. If a user needs to see the entire row in one
shot - you can programm the app so that when the user selects a row in the
main datagridview - it brings up a 2nd form. In this 2nd form is where you
have the 5 temp datagridviews.

In order to keep track of where the user is on the main datagridview, use a
CurrencyManager object. My suggestion(s) here is/are based on the notion
that you are already using a currency manager. If you are not using a
currency manager - you should note that whenever you are using a
datagrid/datagridview you should always be using a currencyManager:


declare at form Level (or globally sometimes in a Module - you can have
multiple currencyManagers)

Dim curMgr1 As CurrencyManager

Private Sub Form_Load(...) Handles Me.Load
....
curMgr1 = CType(Me.BindingContext(dataset.Tables("tbl1"), CurrencyManager)
curMgr1.Position = 0
txtRecordPosition.Text = (curMgr1.Position + 1).ToString
Datagridview1.DataSource = dataset.Tables("tbl1"0
....
End Sub

In the click event of the datagridview, the currencyManager will
automatically update its position (starting at position 0 (zero) - thus I add
a 1 when displaying the position). Make your dataset Application level
(global). On the click event of the datagridview you bring up the 2nd form.
Note: I generally display datagridview recordposition in a statusstrip
lable. Add a statusSTrip from the toolbox to your datagridview (or to the
form). It will automatically dock to the bottom of the form. When you click
on the statusStrip, it will automatically start creating either a
statusLable, or dropdown box, or textbox (very nifty control).


Private Sub dgrv1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles dgrv1.Click
tssL2.Text = (curMgr1.Position + 1).ToString
Dim frm As New Form2
frm.Show
End Sub

In Form2 you have your 5 datagrids. You populate your 5 temp tables from
dataset.Tables("tbl1"). You can pass the selected row from the main form
either to the constructor of Form2 and populate your temp tables directly
from the row or set up a ReadOnly property on your main form that would
contain the selected row and read the selected row from the property when
Form2 comes up, or you can pass in the index of the selected row and use a
Dataview control to find that row in dataset.Tables("tbl1") when in Form2 and
read the contents of the row that way, or you can use an ArrayList to collect
all the values from the selected row and pass the ArrayList to Form2 (I think
the arrayList idea would be the easiest - brain storming here). Say we go
with the ArrayList idea, read in the first 10 items from the list to
tempTable1, then the next 10 items to tempTbl2, tmptbl3, ... then

For i As Integer = 0 to ArrayList.Count
If i < 10 Then
populate tmptbl1
End If
If i >= 10 And i < 20 Then
populate tmptbl2
End If
....
Next

datagridvew1.Datasource = ds.Tables("tmpTbl1")
datagridview2.Datasource = ds.Tables("tmpTbl2")
....

Now you have a static extended dispaly of the selected row with all the
column Headers viewable on one form without having to scroll.

If this seems a little tedious, just remember -- you are the programmer.
This is what you do.

Regards,
Rich
 

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