We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Making the GridControl like the ListView

Thread ID:

Created:

Updated:

Platform:

Replies:

6297 Aug 7,2003 07:10 PM UTC Aug 11,2003 06:42 PM UTC Windows Forms 14
loading
Tags: GridControl
Josh Martin
Asked On August 7, 2003 07:10 PM UTC

Hello... I was wondering which combination of properties i have to change in order to make your grid control look like the stock microsoft listview control. I've got it very close to what i want by ajusting the following through the designer: Allow selection: Row, Alpha Blend Listbox Selection Mode: One Numbered Colheaders: false Numbered Rowheaders: false Properties.RowHeaders: false Show Cell Current Border Behavior: HideAlways TableStyle.CellType: Static I have 2 simple problems at this point. 1: The entire row is selected using the alpha color (good) except the currently selected cell (bad). 2: Is there a simple way to disable the grid's handleing of the Tab keypress so we can switch to the next control. Thanks in advance, Josh

Josh Martin
Replied On August 7, 2003 07:47 PM UTC

Also is there a way to disable the default action holding the control key has. I want my application to be keyboard friendly and there is no way to do multiple selection of items using the arrow keys space and holding control like the listview (and most windows programs) do.

Administrator [Syncfusion]
Replied On August 7, 2003 10:11 PM UTC

1) Handle the grid's CurrentCellActivating event, and in the handler set e.ColIndex = 0. 2) grid.Model.Options.WrapCellBehavior = GridWrapCellBehavior.WrapRow; - If you want to allow mutiple selected rows, then change the ListboxSelectionMode to something other than One or None.

Holger Persch
Replied On August 8, 2003 03:02 AM UTC

A further question to this: How to enable the default listview selection coloring instead of the "Alpha Blend" selection coloring? Regards, Holger

Administrator [Syncfusion]
Replied On August 8, 2003 06:55 AM UTC

If you do not use alphablend selection with standard selections support, then the grid just inverts the range which will not do what you want. So, one alternative, is to turn off the default selections support, add a member to your grid or form that tracks "your selected row". You could maintain this member is CurrentCellMoving or event CurrentCellActivating. Then handle the PrepareViewStyleInfo event, and if e.RowIndex is equal to your selected row, set the e.Style.BackColor to what you want. You might also have to set this.gridControl1.RefreshCurrentCellBehavior = GridRefreshCurrentCellBehavior.RefreshRow to get the whole row to repaint when you move teh currentcell. (If the old row does refresh, you could explicitly call grid.RefreshRange on the old row after your change your current member.) If you are just using SelctionMode.One, then a simple int membmer can serve to hold your selected row and maintain it. If you want to support othe selection modes, mainting the selected rows becomes more problematic (but doable). One alternative might be to just use the grid's default selection with the alphblending set so low that you do not see the selections. Then in PrepareViewStyleInfo, you could check to see if e.RowIndex is a member of grid.Selections, and if it is, then color it.

Josh Martin
Replied On August 8, 2003 12:57 PM UTC

You can turn off the alpha blending by ajusting the grid's controller options property.

Josh Martin
Replied On August 8, 2003 12:58 PM UTC

Clay ... Any ideas on my other 2 questions?

Administrator [Syncfusion]
Replied On August 8, 2003 01:24 PM UTC

I thought I answered your questions in my provious post which is copied below. What questions did I miss? ==================================== 1) Handle the grid's CurrentCellActivating event, and in the handler set e.ColIndex = 0. 2) grid.Model.Options.WrapCellBehavior = GridWrapCellBehavior.WrapRow; - If you want to allow mutiple selected rows, then change the ListboxSelectionMode to something other than One or None.

Josh Martin
Replied On August 8, 2003 07:32 PM UTC

Clay... Thanks for your replys. I tried the suggestions you listed below and neither solved the tab or control (they keys on your keyboard) issues. For clarification here are the problems i am still having: 1- I am working on the keyboard friendlyness of my application and havent been able to find a way to tab out of the grid to the next control on my form. 2- The default behavior of holding down the control key and using the arrow keys makes it very difficult to select individual rows using only the keyboard. Is there a way to disable this functionality? Thanks -Josh- > I thought I answered your questions in my provious post which is copied below. What questions did I miss? > > ==================================== > > 1) Handle the grid's CurrentCellActivating event, and in the handler set e.ColIndex = 0. > > 2) > grid.Model.Options.WrapCellBehavior = GridWrapCellBehavior.WrapRow; > > > - If you want to allow mutiple selected rows, then change the ListboxSelectionMode to something other than One or None. > > > >

Administrator [Syncfusion]
Replied On August 8, 2003 09:42 PM UTC

1) If you want to tab out of the grid into the next control on the form, try setting this property: Me.CustomGridControl1.Model.Options.WrapCellBehavior = GridWrapCellBehavior.NextControlInForm Now if your grid is directly on a form, this is all you have to do. If your grid is on a panel, or groupbox or tabpage or some other container, then you will also have to handle the WrapCellNextControlInForm event and actually move the focus to where you want it in your container. Here is a sample that might help. The sample has 2 grids, the one on the left is parented to the form, and the one of the right is on a panel. Out of the box, just setting the NextControlInForm value, makes the grid on the left behave as expected, allowing you to tab from button1 to the grid to button2. But the grid on the panel does not behave as expected. There you tab from button3 to the grid to button 1, passing over button 4 which is the next button on the panel. The way to handle this problem is to catch the WrapCellNextControlInForm event, and set the focus the way you want it done depending upon the parent container being used. In the sample, there is commented code in the handler that will move the focus on the panel (the way you might expect). The reason the grid architect opted to expose an event to handle this is that he did not want to try to add code to handle arbitary containers. Instead, the default behavior should handle a form as a parent, but if you have something else, then you will have to use the event. 2) In the AllowSelection property, there is a KeyBoard flag you can turn off. I am not sure this what you want though. You can cancel any selection change by handling the grid.Model.SelectionChanging event. In it, you can test to see if the control key is pressed, cancel the action.
private void gridControl1_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
{
	if((Control.ModifierKeys & Keys.Control) != 0)
	{
		e.Cancel = true;
		return;
	}
}

Josh Martin
Replied On August 11, 2003 01:15 PM UTC

Clay... The solution you suggested for tabbing out of a grid does not work when used in conjunction with the solution you provided me to highlight the entire row. When i handle the CurrentCellActivating event and set the colindex to 0 it doesnt even fire the WrapCellNextControlInForm. As for the other solution i think you misunderstood me. What i want to do is disable the default behavior of the control key and the arrow keys (this has nothing to do with selection). Basically what i want to do is be able to hold down the control key and have it scroll 1 row at a time vs 1 page at a time. Thanks again for your replys. -Josh- > 1) If you want to tab out of the grid into the next control on the form, try setting this property: > > > Me.CustomGridControl1.Model.Options.WrapCellBehavior = GridWrapCellBehavior.NextControlInForm > > > Now if your grid is directly on a form, this is all you have to do. If your grid is on a panel, or groupbox or tabpage or some other container, then you will also have to handle the WrapCellNextControlInForm event and actually move the focus to where you want it in your container. Here is a sample that might help. The sample has 2 grids, the one on the left is parented to the form, and the one of the right is on a panel. Out of the box, just setting the NextControlInForm value, makes the grid on the left behave as expected, allowing you to tab from button1 to the grid to button2. But the grid on the panel does not behave as expected. There you tab from button3 to the grid to button 1, passing over button 4 which is the next button on the panel. > > The way to handle this problem is to catch the WrapCellNextControlInForm event, and set the focus the way you want it done depending upon the parent container being used. In the sample, there is commented code in the handler that will move the focus on the panel (the way you might expect). The reason the grid architect opted to expose an event to handle this is that he did not want to try to add code to handle arbitary containers. Instead, the default behavior should handle a form as a parent, but if you have something else, then you will have to use the event. > > 2) In the AllowSelection property, there is a KeyBoard flag you can turn off. I am not sure this what you want though. > > You can cancel any selection change by handling the grid.Model.SelectionChanging event. In it, you can test to see if the control key is pressed, cancel the action. > >
> private void gridControl1_SelectionChanging(object sender, GridSelectionChangingEventArgs e)
> {
> 	if((Control.ModifierKeys & Keys.Control) != 0)
> 	{
> 		e.Cancel = true;
> 		return;
> 	}
> }
> 
>

Administrator [Syncfusion]
Replied On August 11, 2003 04:02 PM UTC

Attached is a sample that uses OnKeyDown in a derived grid to handle both your requests, I think.

Josh Martin
Replied On August 11, 2003 04:58 PM UTC

Clay... Thanks for the sample. I was hoping there was a way to do it without subclassing but since we are going to be wrapping it up in a control anyways this will work fine. Thanks agin, -Josh-

Josh Martin
Replied On August 11, 2003 06:38 PM UTC

Ok almost perfect here ;) I'm still having 1 last problem. When i tab into the grid i am not getting focus unless i actually click in the grid once. If i try to go 100% keyboard (tab from button one to the grid) the arrow keys do not work. However if i click in the grid to select a row (or just click the col headers) i can then tab to button 2, hit tab again to button one, then hit tab again to the grid and the arrow keys work. I can override the OnGotFocus method and it is indeed firing. I've tried doing a manual selection in the OnGotFocus but it still does not work untill i click inside the grid. Thanks, -Josh-

Josh Martin
Replied On August 11, 2003 06:42 PM UTC

Nevermind i found the problem in the keypress handler. Last post... i promise ;)

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;