Hi all,
I am new in using custom controls.
I have created a custom control in my winform application that inherited of ultragrid. I can not paste my codes here but i explain it below:
1. I have set some of properties such as CellClickAction and HeaderClickAction in OnPaint method before base.OnPaint(pe); command that changed the appearance and behavior of the ultragrid.
2. I have added a ContextMenuStrip control with 3 items (Ascending, Descending, None) that should use in Mouse Up event.
3. I have wrote an event handler for Mouse Up event of ultragrid that should find the caption of clicked header (if the user clicked on header) and do a 3way sorting by check and then change the SortIndicator property of that clicked column (if the left mouse button clicked) or show a ContextMenuStrip on that column (if the right mouse button clicked).
4. I have wrote an event handler for Item Clicked event of ContextMenuStrip that sort the grid based on clicked item.
Now the problem is when i want to use my grid in a form.Every things doing slowly and sometimes visual studio become locking or if for example i add a button to the form with MessageBox.Show(""); command on its clicked event handler and then run, and click on this button the form locking.
can any one tell me what is my mistake? please feel free to ask me about my question.
Hi,
You cannot have selected rows in the grid when a cell is in edit mode. And clicking an edit button in a cell requires the cell to enter edit mode. So this is not possible.
You can use the ActiveRow in the grid, but not selected.
Hi mr Saltzman and thanks for your reply.
Excuse me because of my incomplete question.I do not have permission from my boss to paste my codes here.
I solved my problem by removing the commands that I had written to set the ActiveRowAppearance and SelectedRowAppearance properties in OnPaint().
But i believe that you are right, using this event to set property on the control is a very bad idea. because now i have another problem.This custom grid can not distinguish the selected Row in runtime! I mean for example when i am selecting a row at runtime and then clicking the Edit button the selected.Row.Count is equal to zero!
So please suggest me where is the best place to set the properties of the custom ultragrid?
The only thing here that seems like it might cause a performance problem is using the OnPaint event. Unless you are using a flag so that you are setting these properties only once, the first time the grid paints, using this event to set property on the control is a very bad idea.
In fact, I doubt that is the problem, since setting a property to the same value it was already set to is really a no-op. But that's the only thing you listed here that struck me as odd.
My guess is that whatever the issue is, it's probably something else in your application that's causing it. But of course, I can't guess what that is, I can only see what you posted here. Try taking a look at the WinGrid Performance Guide for some advice on common performance issues.