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.

No subject

Thread ID:

Created:

Updated:

Platform:

Replies:

6652 Aug 21,2003 05:04 AM Aug 21,2003 08:05 AM Windows Forms 5
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On August 21, 2003 05:04 AM

I'm working with a GridControl (unbound grid) and I am dynamically building the contents of that grid at runtime. In one of the columns I need to add a combobox to give the user the ability to select from a range of choices. This was fairly easy to accomplish, but what I'd like to do in addition is set the width of the combobox control in the grid. The column width for that particular column is 200 pixels. But, for aesthetic reasons, I'd like to set the width of the combobox to 150 pixels and center it horizontally. This question also applies to other types of controls that I might want to add, such as buttons. Suggestions?

Administrator [Syncfusion]
Replied On August 21, 2003 05:46 AM

To center the combobox in the cell, you can try using the cell style's BorderMargin properties. this.gridControl1.ColWidths[2] = 200; GridStyleInfo style = this.gridControl1[2,2]; style.CellType = "ComboBox"; style.DataSource = dt; style.DisplayMember = "Col1"; style.ValueMember = "Col1"; style.BorderMargins.Right = 25; style.BorderMargins.Left = 25; To change the width of the dropdown itself, you have to handle the CurrentCellShowingDropDown event and set the e.Size.
private void gridControl1_CurrentCellShowingDropDown(object sender, GridCurrentCellShowingDropDownEventArgs e)
{
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if(cc.ColIndex == 2 && cc.RowIndex == 2)
	{
		e.Size = new Size(150, e.Size.Height);
	}
}

Administrator [Syncfusion]
Replied On August 21, 2003 06:39 AM

That works great, but is there anyway to set the background color of the combobox that is rendered? If I set the BackColor porperty of the style that affects the background color for the entire cell, I just want to change it for the control within the cell only (mainly because my default grid color is non-white). My first thought to get around this since I couldn't seem to find an easy way to do this was to build my own ComboBox and add it to the cell (e.g. style.CellType = "Control", style.Control = myComboBox, and add the control to the form's controls collection). When I did this, however, I noticed that my cpu usage rockets to 100% while the combobox cell has the current focus. When I move off the cell to another cell (without my combobox), the cpu usage returns to normal. What is the best way to handle this? Continue tweaking the properties of the built-in ComboBox CellType or figure out the cpu usage issue if I drop a regular WinForms ComboBox control into that cell? Thanks! > To center the combobox in the cell, you can try using the cell style's BorderMargin properties. > > this.gridControl1.ColWidths[2] = 200; > GridStyleInfo style = this.gridControl1[2,2]; > style.CellType = "ComboBox"; > style.DataSource = dt; > style.DisplayMember = "Col1"; > style.ValueMember = "Col1"; > > style.BorderMargins.Right = 25; > style.BorderMargins.Left = 25; > > > To change the width of the dropdown itself, you have to handle the CurrentCellShowingDropDown event and set the e.Size. >
> private void gridControl1_CurrentCellShowingDropDown(object sender, GridCurrentCellShowingDropDownEventArgs e)
> {
> 	GridCurrentCell cc = this.gridControl1.CurrentCell;
> 	if(cc.ColIndex == 2 && cc.RowIndex == 2)
> 	{
> 		e.Size = new Size(150, e.Size.Height);
> 	}
> }
> 

Administrator [Syncfusion]
Replied On August 21, 2003 07:19 AM

Something to try. Add the color you want to your combobox cell. style.BackColor = Color.Red; Then in a CellDrawn event (requires version 1.6 maybe ??), color the rectangles on either end to be the color you want them to be.
              
private void gridControl1_CellDrawn(object sender, GridDrawCellEventArgs e)
{
	if(e.RowIndex == 2 && e.ColIndex == 2)
	{
		Rectangle rect = e.Bounds;
		rect = new Rectangle(rect.Left, rect.Top, 25 , rect.Height );
		e.Graphics.FillRectangle(Brushes.LightPink, rect);

		rect = e.Bounds;
		rect = new Rectangle(rect.Right - 25, rect.Top, 25, rect.Height );
		e.Graphics.FillRectangle(Brushes.LightPink, rect);
	}
}

Administrator [Syncfusion]
Replied On August 21, 2003 07:45 AM

Clever idea, thanks! Now I have more of a general design question for you when working with these grids. To achieve the functionality that I require, so far I require two event handlers to be added to the grid (CurrentCellShowingDropDown and CellDrawn). Since I will need these event handlers to check for more than one cell on the grid (I'm going to add multiple copies of this particular dropdown list on the fly as a user needs them), how best should I handle this? I'm thinking that I will need to maintain a list of which cells these operations should be against and then check that list each and every time these events fire. It doesn't seem like an elegant solution to me. Would you happen to have a better idea? Thanks so much for your help Clay! > Something to try. Add the color you want to your combobox cell. > > style.BackColor = Color.Red; > > > Then in a CellDrawn event (requires version 1.6 maybe ??), color the rectangles on either end to be the color you want them to be. >
              
> private void gridControl1_CellDrawn(object sender, GridDrawCellEventArgs e)
> {
> 	if(e.RowIndex == 2 && e.ColIndex == 2)
> 	{
> 		Rectangle rect = e.Bounds;
> 		rect = new Rectangle(rect.Left, rect.Top, 25 , rect.Height );
> 		e.Graphics.FillRectangle(Brushes.LightPink, rect);
> 
> 		rect = e.Bounds;
> 		rect = new Rectangle(rect.Right - 25, rect.Top, 25, rect.Height );
> 		e.Graphics.FillRectangle(Brushes.LightPink, rect);
> 	}
> }
> 

Administrator [Syncfusion]
Replied On August 21, 2003 08:05 AM

I would probably try to avoid the list if possible just to avoid having to maintain it. Instead, maybe everything you need to know is already available in the style. You can get the style in CellDrawn with the e.Style property. In CurrentCellShowingDropDown, you caould get it with code like: GridCurrentCell cc = this.gridControl1.CurrentCell; GridStyleInfo style = this.gridControl1[cc.RowIndex, cc.ColIndex]; So, if you need to test for say the cell style to do certain actions (say checking the bordermargins in CellDrawn to know whether to draw the border rectangles), then you can just do it without having to maintain a list. If you really need to track additional information that is not part of the style, you could actually add it to the style using the style.Tag property. Then you would have access to it in these events as well.

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.

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.

;