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. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Set ComboBox Cell''s selected item programatically in GGC

Thread ID:

Created:

Updated:

Platform:

Replies:

36959 Nov 14,2005 06:18 AM UTC Nov 14,2005 01:38 PM UTC WinForms 7
loading
Tags: Grouping
Albie
Asked On November 14, 2005 06:18 AM UTC

Hello, I have a GridGroupingControl where I set the celltype in the QueryCellStyleInfo to be a combobox depending on a value in the same row. I also set the datasource of the combobox in the QueryCellStyleInfo, but I want to initialize the combobox to startup with a selected item. Here is a short sample of the code that I use in the QueryCellStyleInfo handler: e.Style.CellValueType = typeof(string); e.Style.CellType = "ComboBox"; e.Style.DisplayMember = "Name"; e.Style.ValueMember = "Name"; DataTable paramTable = tblParameters.Copy(); e.Style.DataSource = GetParameterList(paramTable); I would prefer not to set the datasource everytime the querycellstyleinfo event occur, is this possible and what is the best way to then select an item in the combobox, just after the datasource has been assigned. The behaviour must be similar to selecting an item with the mouse, except that I want to achieve this programatically. Thanx Albie

Administrator [Syncfusion]
Replied On November 14, 2005 09:37 AM UTC

If you want to dynamically set the list in a dropdown in a manner where the dropdown can varies from row to row, then you will have to set the DataSource in QueryCellStyleInfo. To handle setting the initial value of the dropdown cell, you should probably set this every time the ''trigger value'' in the row changes (ie. set it everytime whatever the test value you are using to determine the dropdown changes). So, initially, when you load the data for the grid, you would make sure ths cellvalue for the combobox is properly set. Then, you could listen to the grid.TabelControlCurrentCellValiding event. There, if it is the trgigger cell being changed, you could try changing the combobox cellvalue accordingly.
private void gridGroupingControl1_TableControlCurrentCellValidating(object sender, GridTableControlCancelEventArgs e)
{
	GridCurrentCell cc = e.TableControl.CurrentCell;
	GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(cc.RowIndex, cc.ColIndex);
	if(style.TableCellIdentity.Column != null 
		&& style.TableCellIdentity.Column.Name == "triggerCol"
		&& style.TableCellIdentity.TableCellType == GridTableCellType.AnyRecordFieldCell)
	{
		//new trigger value
		string s = cc.Renderer.ControlText;

		//get the record
		GridRecord rec = style.TableCellIdentity.DisplayElement as GridRecord;
		rec.SetValue("comboBoxCol", "someValueBasedOnTheValueOf_s_");
	}
}

Albie
Replied On November 14, 2005 12:12 PM UTC

Thank you Clay. I will definately have to consider this as well, but my problem starts a bit sooner, as I show in the following block of code, which is all in the QueryCellStyleInfo handler. e.Style.CellType = "ComboBox"; e.Style.DisplayMember = "Name"; e.Style.ValueMember = "Name"; DataTable paramTable = tblParameters.Copy(); e.Style.DataSource = GetParameterList(paramTable); //Set the selected item here... I have looked at the e.Style.SetValue(e.Sip,"My Value") method, but the e.Sip property is null. What is the appropriate way to set the selected item in the combox cell for which the datasource was assigned in the QueryCellStyleInfo?

Administrator [Syncfusion]
Replied On November 14, 2005 12:18 PM UTC

You can directly set the proeprty, CellValue. e.Style.CellValue = someValue; But you have to take care putting such code in QueryCellStyleInfo if you want the cell value to vary. In such cases, you have to avoid hitting the code, or you have to make sure ''someValue'' changes when you want the cell value to change. Otherwise, the only thing you will ever see in the cell is someValue.

Albie
Replied On November 14, 2005 12:25 PM UTC

Yes, and this is part of my problem. The moment the user selects a different entry in the combobox, the QueryCellStyleInfo should not set the value anymore, do you have any ideas on how to implement this. How does the mouse event achieve this, because, even thoug you assign the datasource over and over a gain, the combobox stil "remembers" the last selected item if the mouse is used to select an item. Thanx Albie

Administrator [Syncfusion]
Replied On November 14, 2005 12:25 PM UTC

Here is a forum thread that conditionally displays a dropdown gridlistcontrol in a child table depending upon a value in the parent record of the childtable. You could do something similar based on some value in the same row. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=36766

Albie
Replied On November 14, 2005 01:04 PM UTC

Thank you Clay. I already have a grid that works fine with the celltype and datasource being set depending on a cellvalue in the row. The problem is that if the current cell is a dropdown, I have to set the value of that dropdown cell to a specific member, OnInitialize of the grid. Thus the grid is loaded with several comboboxes and each one has a different item selected at startup. When the user now uses the mouse to override the initial selection the dropdown must not set the selected item programatically. Which event can I use to catch the user(Mouse) selection of the dropdown cell? Must I maintain a global variable that determines if a dropdown''s selected item was chosen by the user(Mouse) and then on condition of that set the value of the dropdown programatically?

Administrator [Syncfusion]
Replied On November 14, 2005 01:38 PM UTC

>>The problem is that if the current cell is a dropdown, I have to set the value of that dropdown cell to a specific member, OnInitialize of the grid. You should set the proper value in whatever the grid''s datasource is. So, without using the grid, loop through the records in the datasource and set the value in the combobox column to be what you need. This can probably be done without any interaction with the grid as the grid plays no role in what the initial values of the cells are. Then later, as your user changes the trigger value in the grid, you can use the TableCOntrolCurrentCellvalidating event as discussed above to change the value in the DataSource to be the apppropriate value. This way the datasource always has the proper value, and the grid should just show this proper value.

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

;