Click to See Complete Forum and Search --> : Listview
Sigal Laniado
July 22nd, 1999, 09:45 AM
I want to change the column header of a ListView. I need to have two lines. The first is the column header and in the second line for each column i need a text box or combo box that goes togeher with the column header. Is any one has any idea of how to start to doing this. I need only instruction for starting this...
Ravi Kiran
July 23rd, 1999, 12:57 AM
Go for MS FlexGrid.
It allows you to have multiple-rowed Column headers - what he calls as Fixed Columns.
You case is different. You may have to look at how to position Text boxes and Combo boxes in FlexGrid's Cells, for your requirement.
You can do this with Listview also but goes into subclassing etc, which is difficult.
Chris Eastwood
July 23rd, 1999, 03:14 AM
There's an article at http://www.codeguru.com/vb/articles/1749.shtml that shows how to create an 'editable' MSFlexGrid - it would make a good starting point.
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb
Lothar Haensler
July 23rd, 1999, 03:29 AM
IMHO there is a much better implementation in the VB programmer's guide for VB 6.
Check out section "Editing Cells in a Hierarchical FlexGrid Spreadsheet".
Still, all those approaches suck. Did you ever click on the scrollbar of the grid, when the textbox was active?
Or change the font? or....
IMHO, if you need an editable grid, buy one or use the DB grid in unbound mode.
Chris Eastwood
July 23rd, 1999, 04:04 AM
Hi Lothar
I've had to create a grid control at work that's based on the MSFlexGrid, none of the third party controls out there had what we needed at the time - it had to be editable with different type of controls (combo, textbox, usercontrols etc), it also had to support 'hidden' columns, drag&drop between/within grids, and multiple selection of individual rows (which you can't do with the FlexGrid, so I had to rewrite all the highlighting!) - the handling of focus for hiding the usercontrol is a nightmare but I managed to get around it in the end. Even resizing a column in the FlexGrid is difficult to detect (although you can fudge it with subclassing).
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb
Ravi Kiran
July 23rd, 1999, 04:05 AM
Ofcourse you will have to handle the scroll events when the Edit box is ON. I have done it for my prev. project. It seems to work decently fine.
Like, when the data is being edited, say date field, the user suddenly scrolls the s-bar, and i validate the text box input. If the validation fails (!), i have to set the scroll position back correclty and set back the focus to text box and all that.
True. It is not simple & staright forward with FlexGrid.
But doing the editable DB grid with Combobox Or listbox is no joke either!. Only for text box case, it is easy
Lothar Haensler
July 23rd, 1999, 04:13 AM
that sounds really interesting.
Where did you publish that code?
Ok, just kidding :-)
(I wouldn't publish it either, I'd rather sell it)
Chris Eastwood
July 23rd, 1999, 04:36 AM
;-)
It's a very cool control - it's being used in production app's at the moment. I'd love to publish the code on the net but it's (technically) owned by my employers, although as I'm looking for a new job - who knows!
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb
Ravi Kiran
July 23rd, 1999, 04:44 AM
OK. You want to give me some money.. please do:-)
I will show you a piece of that code. Stripping unnecessary code from that project was not easy.
I hope this give the idea:
private Sub grdDataEntry_Scroll()
If ModeNowEditing then
If AcceptEditVals(true) = false then
Beep
With grdDataEntry
.Row = m_EditStruct.iCellid_row
.Col = m_EditStruct.iCellid_col
.LeftCol = m_EditStruct.iLeftColumn
End With
End If
End If
End Sub
The bold & itelised stuff do the trick of restoring the scroll bar back to its place!!
Obviously, at the start of editing you have to save the 3 values. Also my grid had fixed rows and hence no VScroll. Otherwise you might have to store that value also, in order to get back properly
Ravi Kiran
July 23rd, 1999, 04:48 AM
Hi Lother,
Sorry i got confused in the "Flat Threaded Mode".
I didn't see properly that your money offer was for Chris's comment :-) LOL**
Lothar Haensler
July 23rd, 1999, 05:16 AM
never mind, just publish your bank account and I send you the 2 cents :-)
no, just kidding.
What I was trying to say is, that it's just too much effort to implement everything to make your editable grid a truly working grid.
That's my personal opinion.
Sigal Laniado
July 25th, 1999, 02:18 AM
Hi Chris,
I have tried to use the MSFlesGrid for my needs - but with no success. I am really do not what to do. I don't need to edit a cell in the table. My list is not editable. The only thing that the user can change is the column header.
The column header should have 1 fix row for the header and the second row with edit box or combo box. The second line is for filtering the column (the user will type a word in a cell in the second row and the column will be filtered).
The user can change the order of the columns header (both lines) and can change the size of each cell.
When the user scroll the two lines columns will remain.
I know that i need to do it by my own and i am begining to learn VB just now.
So i will apprciate any help on this !!!... Thank you.
Can you tell me how you did the multiple selection, hidden columns...
Thanks.
Sigal Laniado
July 25th, 1999, 02:39 AM
Thanks. Do you know a good article/source for subclassing...
Sigal
Ravi Kiran
July 26th, 1999, 12:32 AM
Hi,
If you dont have dynamic editing , i.e any cell, it is even more easy, is int it?
just put textbox or Combobox, Statically, in all the cells of 2nd row, i mean on-top-of all cells on 2nd row.
Make the .FixedRows = 2, so that thy will remain even if user scrolls.
Try this code. It works:-)
Take a form. Put a MSFlexGrid. Put a check box.
Put 2 text boxes and 1 combo box. All default names.
Cut and paste this code.
private Sub Check1_Click()
Debug.Assert me.ScaleMode = vbTwips ' otherwise positions will get messed up
If Check1.Value = 1 then
With MSFlexGrid1
.Col = 1: .Row = 1 ' set the curnt cell
Text1.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth, .CellHeight
.Col = 2: .Row = 1 ' set the curnt cell
Combo1.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth ', .CellHeight
.Col = 3: .Row = 1 ' set the curnt cell
Text2.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth, .CellHeight
End With
else
Text1.Move Text1.Left, MSFlexGrid1.Top - Text1.Height
Combo1.Move Combo1.Left, MSFlexGrid1.Top - Text1.Height
Text2.Move Text2.Left, MSFlexGrid1.Top - Text1.Height
End If
End Sub
private Sub Form_Load()
MSFlexGrid1.Rows = 20
MsFlexGrid1.FixedRows = 2
Check1.Caption = "Move edit controls on to 2nd column"
End Sub
As you check & uncheck the check box, you will see that the controls jump up & down.
Scroll also works properly. Make .Rows more if required, to test.
This is a little rough logic. You may have to fine tune it: Like when the user drags the cells you have to adjust the positions. This logic in its present form works, if the columns are dragged when the controls are outside, and positioned back by Check1 click
Sigal Laniado
July 26th, 1999, 02:45 AM
Thank you very very much. It is really help me to start understanding the idea- but there is one problem with your code that i am tring to solve is that the MSFlexGrid appear on top of the text box (the text box is under the second row and not visible). Do you have a quick solution ?
Thank you for everything.!!
Chris Eastwood
July 26th, 1999, 02:52 AM
You need to set the ZOrder of the textbox/other control that you want to display on top of the Grid,
eg.
Text1.ZOrder
- as for the Multiple Selection - I had to manually track each Click on the grid and store the selected row in an array/collection. You also have to remember to check the keystate when the user clicks the mouse to make sure you follow standard windows 'rules' for multiple selection (ie. Shift + select, CTRL + select etc).
The repainting is slightly more tricky as you need to turn off all highlighting in the grid and paint it yourself - the CellBackColor property allows you to make the rows appear as selected.
It was a lot of work - make sure you really have the time to implement all of this before you jump straight in.
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb
Sigal Laniado
July 26th, 1999, 05:47 AM
Thank you a lot!
Is it more easy to do dbl-click in a ListView and not in MSFLEXGrid
Sigal Laniado
July 26th, 1999, 05:54 AM
Can i do the same with a ListView : to update the height of the column header to occupy 2 rows and then to put the controls on the column header at the bottom of the title. Do you know how to change the height of the ListView's columnheader?
Ravi Kiran
July 26th, 1999, 07:27 PM
Hi,
I too am trying for the same :-), increase the height of Column header. It doesn't seem possible yet.
If you care for details:
Listview header is a control by itself - Header Control of Common Controls set, that does this default processing of drag etc. Each item of it has a structure HD_ITEM. You can fill this structure and send a message to header so that it takes appropriate action.
Like:
SendMessage hWndHdr, HDM_SETITEM, 1, tmpHDItem
It is defined like this:
public Type HD_ITEM
mask as Long
cxy as Long
pszText as Long
hbm as Long 'HBITMAP hbm;
cchTextMax as Long 'int cchTextMax;
fmt as Long 'int fmt;
lParam as Long 'LPARAM lParam;
iImage as Long 'int iImage; // index of bitmap in ImageList
iOrder as Long 'int iOrder; // where to draw this item
End Type
There is only one member Cxy and the mask can take these two values (along with others too)
when you want to set the width & height.
public Const HDI_WIDTH = &H1
public Const HDI_HEIGHT = HDI_WIDTH
In the CommCtrl.h file the height constant is set to Width!!. So all that you can do is only change the width by that HD_SETITEM message. I tried and it works only for width.
Right now i am looking into MSDN. Will let you know if something comes up.
Ravi Kiran
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.