|
There seems to be a bug when you specify a grid to be larger than the length of it's columns. The grid control turns gray and nothing is drawn. I am using Windows XP, Service Pack 2.
The problem is caused by the scroll window being not shown, but the scroll information is never updated.
In the void RecalcWindow(HWND hWnd) function:
else
ShowScrollBar( hWnd, SB_HORZ, FALSE );
at the top of the function should be:
else
{
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL;
si.nPos = GetScrollPos( hWnd, SB_HORZ );
si.nMin = 0;
si.nMax = sizeX - scrollDiff;
si.nPage = si.nMax - si.nMin + 1 - abs(scrollDiff);
si.nTrackPos = 0;
SetScrollInfo( hWnd, SB_HORZ, &si, TRUE );
ShowScrollBar( hWnd, SB_HORZ, FALSE );
}
And:
else
ShowScrollBar( hWnd, SB_VERT, FALSE );
at the bottom of the function should be:
else
{
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL;
si.nPos = GetScrollPos( hWnd, SB_VERT );
si.nMin = 0;
si.nMax = sizeY - scrollDiff;
si.nPage = si.nMax - si.nMin + 1 - abs(scrollDiff);
si.nTrackPos = 0;
SetScrollInfo( hWnd, SB_VERT, &si, TRUE );
ShowScrollBar( hWnd, SB_VERT, FALSE );
}
That's what I have right now which makes the control behave how it should. I've not used it much due to this bug, but if I find more I will post.
|
|
|
|
|
Hey!
What kind of license are you using for this great control? Would you mind if I used it in a couple of projects?
-R
|
|
|
|
|
Hi darkoman,
Do you plan to continue development ?
When an updated and enhanced version will be released ?
Thanks
spyto
|
|
|
|
|
Hellow, the DataGrid is very useful, but how can I resize it when I resize the dialog?
Find the Way!
|
|
|
|
|
Just re-size it like any other window using the MoveWindow function and use the GetWindowHandle in DataGrid class for the first argument for MoveWindow.
Then use GetClientRect for the dialog's 'HWND' to get the size.
|
|
|
|
|
In a mfc program, this class works not very well.
void CTest11Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
RECT rect = {50,50,670,300};
CDataGrid dataGrid;
dataGrid.Create( rect, this->m_hWnd, 5 );
// Set DataGrid column info
dataGrid.SetColumnInfo( 0, "Column0", 120, DGTA_CENTER );
dataGrid.SetColumnInfo( 1, "Column1", 120, DGTA_CENTER );
dataGrid.SetColumnInfo( 2, "Column2", 120, DGTA_CENTER );
dataGrid.SetColumnInfo( 3, "Column3", 120, DGTA_CENTER );
dataGrid.SetColumnInfo( 4, "Column4", 120, DGTA_CENTER );
dataGrid.Update();
}
The grid is invisible in this procedure.
When the total columns width less than the grid width, the grid will be invisible in MFC procedures. in other words, if no vertical or horizontal scrolling of the scroll appears, the grid will be invisible. However, in Win32 procedure does not exist in this issue.
Thank you!
|
|
|
|
|
First of all, thank you for your work! This class is practical, and very brief.
I would like to ask you how to delete n column or delete all columns?
Thank you!
|
|
|
|
|
Which step that you want delete DataGrid's column?
Before DataGrid DataBind:
You can control DataSet or DataTable or ArrayList!
After DataGrid DataBind:
First, You can give DataGrid's column a id when DataBind by event OnItemDataBound.
Second,You can contol hidden or show by javascript(document.getElementById(id).style.display).
My English not very well,Are you understand?
|
|
|
|
|
First of all, thank you for your attention!
I need the works based on the user's choice of different values, and in tabular form displayed.
First time user may measure sample1 value and sample2 value, so column1 = sample and column2 = Sample2.
After read all the data and display the future, user may have to sample3 and sample4 or other values, so I want to clear all the Items and Columns, and re-create Columns. Then read data and show it again.
|
|
|
|
|
If you want to read data and show it again,you should re-creat page and re-DataBind or use ajax.
Sorry,I used ajax hardly! You can read some books about ajax!But,If you want to How to re-DataBind,please tell me!
|
|
|
|
|
I have been resolved this question.
|
|
|
|
|
Hi, darkoman, I like your control style very much. But when I test it in unicode, many error occurs. I've changed the code as you suggested before.
eg: _tcscpy( dgList->dg_Columns[i].columnText, " ");
error C2664: 'wcscpy' : cannot convert parameter 1 from 'char [1024]' to 'wchar_t *'
Can you give me some more advice? Or can you kindly test the code in unicode?
sorry for my poor English! : )
Find the Way!
|
|
|
|
|
Hello, thanks for your interest...
I think that you'll need just to convert dgList->dg_Columns[i].columnText variable to _TCHAR* and it should work. I mean both params in _tcscpy() method have to be of the _TCHAR* type.
Hope it will work for you...
Best regards,
Darkoman
|
|
|
|
|
Hello, thanks for your advice, now it works well in unicode! I'm so happy!
Find the Way!
|
|
|
|
|
I am thinking of using this datagrid for my project. There are two features missing which I need i.e. multiple row selection and intelligent paging.
I was wondering if any work has been done on them. If not I am willing to spend some time to add these features, but want to make sure if the design of the grid will support multiple row selections? I have not looked at the source yet.
|
|
|
|
|
Hello and thanks for your interest in this project,
Sorry, but no work has been done (no time to work further) on the multiple row selection or paging.
Yes, you are free to add these features to the project. The grid design would allow support of multiple row selection (with no major changes).
Best luck...
Regards,
Darkoman
|
|
|
|
|
I have seen you data grid project and willing to ask you that if I click on any row i want the number(count) of the row where it exist as i need some sort of looping for my application
for(int i= clickedRow ; i < totalrows; i++ ) for enhancing my UI
I am able to get the total number of rows via
long totalRows = m_dataGrid.get_ApproxCount();
Would you please help me
Thnaks in advance
Kaz
It is Kaz
|
|
|
|
|
I'm trying to create a second instance of the grid in another dialog but i'm having redefinition error for the structs(DG_COLUMN..) I tried to move their definition to another file but that didn't help. Any help?
Thanks,
hope.
|
|
|
|
|
Hi Darkoman,
That's me again. Now I have probably simple problem, but I can't solve it. I have created simple application with main window and status bar. In a workspace between menu and statusbar Grid is located. Now, when window is resized then Grid is also resized, but it overlaps with status bar or there is a space between them. Any suggestion to solve this problem??
Regards
WojciechW
|
|
|
|
|
if debug,it has no error.But I built it in release."remove all",then duobled click on datagrid control,then it pop out a error"unknow software exception(0c0000094)".
|
|
|
|
|
Hi I'm using your grid in my application, and as others have said, thanks for all your hard work. I'm making some modifications (as my application is slightly odd) and am trying to implement Hidden Rows, i.e. I've added an attribute to each row which when set the row is not redrawn, instead the next one is (unless that is hidden, and so on). Frankly, as I'm not an expert Windows programmer, I'm having trouble! Perhaps this is something you would consider adding yourself?
Also I noticed a problem where the vertical scroll bar "bounces" when dragged to the bottom. This seems to fix it:
case SB_THUMBTRACK:
{
RECT rowRect, clientRect, columnRect;
GetRowRect( hwnd, 0, &rowRect );
GetColumnRect( hwnd, 0, &columnRect );
GetClientRect( hwnd, &clientRect );
clientRect.top = columnRect.bottom;
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL;
GetScrollInfo( hwnd, SB_VERT, &si );
int OldPos = si.nPos;
int NewPos = si.nTrackPos;
// Rick these two lines cause the vertical scrollbar bounce
// which occurs when the scroll bar is dragged to the bottom
//int diff = NewPos % (rowRect.bottom-rowRect.top-1);
//NewPos -= diff;
si.nPos = NewPos;
si.nTrackPos = NewPos;
SetScrollPos( hwnd, SB_VERT, NewPos, TRUE );
InvalidateRect( hwnd, NULL, TRUE );
UpdateWindow(hwnd);
Any comments?
--Ricko
|
|
|
|
|
Hello, thanks if you find it usefull. Yes, I can do this small fix in the next two or three days so I will post an update.
Best regards...
|
|
|
|
|
Wow - that'd be great!
FYI the issues I've identified are:
(1) when the user clicks on a row to select it, converting the click position to the correct row given that there may be hidden rows. For example,
Row 1,2,3,8,9,10 are displayed (rows 4,5,6,7 are hidden)
Click on the 4th visible row, that means that row 8 has been selected.
(2) The vertical scrollbar must be resized depending on the number of visible rows
(3) Select Next/Prev must select the Next / Prev visible row
(4) When the currently selected row is hidden, it needs to be "un-selected"
(5) EnsureRowVisible needs to take account of hidden rows
Items (1) and (5) have got me stumped.
Item (2) required that a count is kept of the number of visible rows as well as the total number of rows. Keeping this in sync is a bit nasty when rows are added, removed, hidden and unhidden.
I look forward to the update! Thanks.
--Ricko
|
|
|
|
|
Nice work, you got my 4. Not many are willing to do this kind of thing in Win32; even fewer are willing to share their code for free. Love the grid, but I have a few suggestions for you. Ignore these if you've heard them before.
- Try drawing only those cells that are visible. You can greatly speed up the responsiveness of the grid when there are 500+ cells.
- Try to implement more functions as windows messages. This would make wrapping your control in an MFC, WTL, or other object windows environment much easier.
- Provide a UNICODE implementation. I see an earlier post suggesting this; you're right, it is simple to do.
- Consider XP theming. It's very easy to implement and adds a lot of visual bang for the buck.
- Build yourself a way of subclassing the edit box and any other controls you wish to use for editing the grid. This way you can catch things like the Enter, Escape, and Tab keys and perform appropriate actions in the grid.
- Implement a handler for WM_GETDLGCODE. This way users putting your grid in a dialog can still get the standard behavior for any keyboard input on the grid.
Thanks again for your hard work, I appreciate it.
Sharpmike
|
|
|
|
|
Hello, thanks for these very good sugestions. I am going to implement most of these things in the next release of the DataGrid. Now, I am on the secret SWF-PROJECT (not present here on CodeProject), so it will take some time.
Considering cell drawing, well, only visible cells are drawn on the screen, otherwise if there are more then 500 cells it would be a problem. I am performing that kind of calculation before I do any drawing.
Best regards...
|
|
|
|
|