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

GridBoundColumn assignment error

Thread ID:

Created:

Updated:

Platform:

Replies:

9987 Jan 20,2004 09:31 AM UTC Jan 23,2004 12:51 PM UTC Windows Forms 22
loading
Tags: GridControl
Rob Panosh
Asked On January 20, 2004 09:31 AM UTC

Hello, I have a GridDataBoundGrid that has a datasource of a strong typed collection which inherits CollectionBase. This collection is filled with myCustom objects. The Grid has three columns, the second column has a Style.CellType of "ComboBox" and its Style.CellType.DataSource is set to a DataTable with a DisplayMember (Text) and ValueMember ( Integer ). The other two columns are just text. When I open my form the Grid populates with no problems. I can change the first and 3rd columns and the value is pushed back into the StrongedTyped collection item, verify by walking in the debugger. The problem is when I select a new value, in the 2nd column, using the combobox then click into another cell, which cause the combobox value to save (note the debugger never makes it to my public property in myCustom object in the collection like it does when the other two columns change) The following error message is shown: "Cannot Widen from Target type to Primitive type" Please advise. Thanks, Rob Panosh Sample Grid Column Code: gridColumn = New Syncfusion.Windows.Forms.Grid.GridBoundColumn gridColumn.HeaderText = "Criteria" gridColumn.StyleInfo.CellType = "ComboBox" gridColumn.StyleInfo.AutoSize = True ''This is a System.DataTable return from ''my associated business object. gridColumn.StyleInfo.DataSource = Me.BusinessObject.RelationOperators gridColumn.StyleInfo.DisplayMember = "fmdescription" gridColumn.StyleInfo.ValueMember = "fmrefqueryrelopsid" gridColumn.MappingName = "CriteriaValueOperator" gridColumn.StyleInfo.Format = " " gridColumn.Tag = 0I me.GridDataBaseConditions.GridBoundColumns.Add(gridColumn) Here is my SQL table that is used as the gridCol.StyleInfo.DataSource: Create table fmrefqueryrelops ( fmrefqueryrelopsid numeric(10,0) not null, fmdescription varchar(20) not null ) insert into fmrefqueryrelops values (0, ''Equal'' ) insert into fmrefqueryrelops values ( 1,''Not Equal'' ) insert into fmrefqueryrelops values ( 2,''Greater Than'' ) insert into fmrefqueryrelops values ( 3,''Greater Than Equal'' ) insert into fmrefqueryrelops values ( 4,''Less Than'' ) insert into fmrefqueryrelops values ( 5,''Less Than Equal'' ) insert into fmrefqueryrelops values ( 6,''Begins With'' ) insert into fmrefqueryrelops values ( 7,''Ends With'' ) insert into fmrefqueryrelops values ( 8,''Contains'' ) insert into fmrefqueryrelops values ( 9,''Does not contain'' )

Administrator [Syncfusion]
Replied On January 20, 2004 11:23 AM UTC

Make sure the property names you are using for the combobox valuemember and displaymember are exactly the same names used in the datasource for the combobox. These are case sensitive. Also, make sure the style.CellValueType for the column is exactly the same type as the valuemember column in the datasource for the combobox. What version of the grid are you using? In the 2010 beta, there was a problem with the GridDataBoundGrid losing its GridBoundColumn collection. If you are using that version, you should try the 2020 beta.

Administrator [Syncfusion]
Replied On January 20, 2004 11:27 AM UTC

>Make sure the property names you are using for the combobox valuemember and displaymember are exactly the same names used in the datasource for the combobox. These are case sensitive. Also, make sure the style.CellValueType for the column is exactly the same type as the valuemember column in the datasource for the combobox. > >What version of the grid are you using? In the 2010 beta, there was a problem with the GridDataBoundGrid losing its GridBoundColumn collection. If you are using that version, you should try the 2020 beta. We are using 2.0.2.0

Rob Panosh
Replied On January 20, 2004 11:53 AM UTC

Clay, Everything matches up ... I have attached the strong type collection used to populate the grid for you to review. When using collections with grids do you have to write any additional code in the dereived collection? Rob sample_1554.zip

Administrator [Syncfusion]
Replied On January 20, 2004 11:59 AM UTC

>>gridColumn.StyleInfo.Format = " " Is that a blank in your format setting? You should try commenting that out to see if that makes things behave better? Also set the gridColumn.StyleInfo.CellValueType = typeof(int) if an int is what the CellValue is. This thread has a little sample that does more or less exactly what you describe except the combo dataspource is also a collectionbase. Maybe it will help spot the problem. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=9977

Rob Panosh
Replied On January 20, 2004 12:23 PM UTC

>Also set the gridColumn.StyleInfo.CellValueType = typeof(int) if an int is what the CellValue is. This doens''t work: gridColumn.StyleInfo.CellValueType = System.Type.GetType("System.Int32") >>>gridColumn.StyleInfo.Format = " " Nope didn''t fix the problem. I will take a look at the example. Rob >>>gridColumn.StyleInfo.Format = " " > >Is that a blank in your format setting? You should try commenting that out to see if that makes things behave better? > >Also set the gridColumn.StyleInfo.CellValueType = typeof(int) if an int is what the CellValue is. > >This thread has a little sample that does more or less exactly what you describe except the combo dataspource is also a collectionbase. Maybe it will help spot the problem. >http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=9977 > >

Administrator [Syncfusion]
Replied On January 20, 2004 01:42 PM UTC

Here is a VB version. forum_9977_VB_1226.zip

Rob Panosh
Replied On January 20, 2004 01:48 PM UTC

Clay, Found the problem. My Property in myObject was strong typed as a System.Int32 and the StyleInfo.ValueVember, was coming from a datatable, and was strong typed as a Decimal. Is there an event that I can trap right before the combobox in the cell assigns the value back to the grid.MappingName? Thanks, Rob

Administrator [Syncfusion]
Replied On January 20, 2004 02:57 PM UTC

Try CurrentCellValidating. It is a cancelable event. You can get things like row and column from the grid.CurrentCell. You can get the newvalue from grid.CurrentCell.renderer.ControlText.

Administrator [Syncfusion]
Replied On January 20, 2004 03:50 PM UTC

Thanks ... works perfect ... stupid question but how the heck do I get a column object for the current column I am editing? Rob >Try CurrentCellValidating. It is a cancelable event. You can get things like row and column from the grid.CurrentCell. You can get the newvalue from grid.CurrentCell.renderer.ControlText.

Administrator [Syncfusion]
Replied On January 20, 2004 04:03 PM UTC

ignore my last question ... I figured it out me.GridDataBaseConditions.GridBoundColumns.Item( me.GridDataBaseConditions.CurrentCell.Renderer.ColIndex - 1) Ok CurrentCellValidating can cancel the assignment of the value but what if I want to manually assign the value. If I manually assign the value in CurrentCellValidating and return e.Cancel = TRUE then the user can''t leave the cell unless they press ESC. Rob

Administrator [Syncfusion]
Replied On January 20, 2004 06:09 PM UTC

You set grid.CurrentCell.Renderer.Control.Text and do not set e.Cancel = true. (Note the above is Control.Text and not ControlText). This will change and save the current value.

Administrator [Syncfusion]
Replied On January 21, 2004 08:59 AM UTC

Clay, I want to be able to control where the value is assinged in the associated collection. For example I want my users to be able to add columns on the fly. These columns will be pointing to the same item in the collection but the values will be stored in an array element within the item. So as you can see I need the ability to manually assign the value. Rob >You set grid.CurrentCell.Renderer.Control.Text and do not set e.Cancel = true. (Note the above is Control.Text and not ControlText). This will change and save the current value.

Administrator [Syncfusion]
Replied On January 21, 2004 09:33 AM UTC

CurrentCellValidating and other CurrentCell events are about saving values to the grid (or the grid''s DataSource). They are not necessarily about saving values to the datasource of a combobox column. It sounds like that is what you want to do, correct? If so, how does this affect what is saved into the grid (or the grid''s datasource). If it does not affect this, then you could just let the grid do its thing to save the value the way it normally does, and then you could pick some event and just modify the combobox datasource in any manner you want. It is likely that you may want to choose a spot like CurrentCellEditingComplete or CurrentCellMoved which is hit after the grid has finished its normal saving routine. Another option would be to handle CurrentCellShowingDropDown and CurrentCellCloseDropDown, and dynamically provide the combobox datasource at this point. This give the greatest flexibilty since the datasource for any cell is set immediately before the combobox is dropped.
private void gridDataBoundGrid1_CurrentCellShowingDropDown(object sender, GridCurrentCellShowingDropDownEventArgs e)
{
	GridCurrentCell cc = this.gridDataBoundGrid.CurrentCell;
	if(cc.ColIndex == 2)
	{
		GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;
		if(cr != null)
		{
		((GridComboBoxListBoxPart)cr.ListBoxPart).DataSource = this.dataTable1;;
		}
	}
}

Administrator [Syncfusion]
Replied On January 22, 2004 02:38 PM UTC

Clay, Essentially what I am trying to do is have multiple columns that all point back to the same Item in my associated datasource (strong typed collection) then each column would save their respective values back to an array element inside the Item Object. I thought I could do this if I could get in front of the assignment and and manually assign the values, ignore the automatic assignment. Rob

Administrator [Syncfusion]
Replied On January 22, 2004 02:41 PM UTC

Additional comment ... when I say datasource I mean the grids underlying datasource not the datasource that was used to populate the combobox. Rob

Administrator [Syncfusion]
Replied On January 22, 2004 04:14 PM UTC

I think this can be done but before I work on a little sample to verify it, let me make sure I understand what you want. Say you have an object, MyObject with three public properties, A, B, and C. You then have a GridDataBoundGrid that has 3 columns, and these columns contain instances of MyObject as values in the columns. When the columns are displayed, instead of seeing th MyObject.ToString text displayed, in 1 column you want to see MyObject.A.ToString displayed, in another column you want to see MyObject.B.ToString displayed, and in the final column MyObject.C.ToString. Additionally, you want these grid columns to be combobox cells where the drop list shows some collection of MyObjects in a muticolumn dropdown, and similar for the other two columns in the grid. Is this what you want?

Administrator [Syncfusion]
Replied On January 22, 2004 05:32 PM UTC

I don''t think you understand what I am trying to do. 1) I have a strong typed collection. 2) This collection is populated with QueryItem Objects. QueryItem Object Properties: Name Values() <-- This is an array Grid Sample: ----------------------------------------- Name Value Or.... Or... ----------------------------------------- FirstName Rob Joe Jack ... ... ----------------------------------------- The above Or... columns can be dynamically added at runtime. Values() would be used to populate Value and the two Or columns. So I would have to essentially access the property then the array element to store Rob, Joe and Jack Could I call you to clarify this? Thanks, Rob >I think this can be done but before I work on a little sample to verify it, let me make sure I understand what you want. > >Say you have an object, MyObject with three public properties, A, B, and C. You then have a GridDataBoundGrid that has 3 columns, and these columns contain instances of MyObject as values in the columns. When the columns are displayed, instead of seeing th MyObject.ToString text displayed, in 1 column you want to see MyObject.A.ToString displayed, in another column you want to see MyObject.B.ToString displayed, and in the final column MyObject.C.ToString. > >Additionally, you want these grid columns to be combobox cells where the drop list shows some collection of MyObjects in a muticolumn dropdown, and similar for the other two columns in the grid. > >Is this what you want?

Administrator [Syncfusion]
Replied On January 22, 2004 05:50 PM UTC

Phone support is reserved for users with valid subscriptions who have submitted a Direct Trac support incident on the matter. I think I understand what your data is now. QueryItem.Values is a collection of objects, and you want to see these objects as columns in a grid that also shows other properties from the particular QueryItem object for this particular row. Is this correct? So, you want a flat looking table with the values in QueryItem.Values displayed out across the same row. Where does the combobox come into this picture? If this is what you want, then the simplest way to do this would be to use a GridControl in virtual mode. This would be straight-forward (I think). If this is what you need, let me know and I will try to post a sample.

Administrator [Syncfusion]
Replied On January 23, 2004 08:51 AM UTC

Clay, >Phone support is reserved for users with valid I can submit a direct trac. It is going to be very hard to explain exactly what I am trying to do here. All I really need to know is Can I control the population of desired column/cells and the assignment back to the grids datasource ... If so could you just supply me the Events needed then I can write the logic. Example: -------- If I had three columns A,B, and C. I would want the Grid to automattically populate A and B using the MappingName and for Column C I would''t supply a MappingName so I could manually handle the data. Rob

Administrator [Syncfusion]
Replied On January 23, 2004 10:45 AM UTC

You can have unbound columns in a GridDataBoundGrid, and populate them from whereever you like, and save changes to them back to your data source. You use teh Model.QueryCellInfo and Model.SaveCellInfo events to manage this behavior. The sample, Syncfusion\Essential Suite\Grid\Samples\DataBound\GDBGMultiHeader, has unbound columns that are managed through these events.

Administrator [Syncfusion]
Replied On January 23, 2004 12:33 PM UTC

Why do I have to use the events off the Model? These events exist off the GDBG. Rob >You can have unbound columns in a GridDataBoundGrid, and populate them from whereever you like, and save changes to them back to your data source. You use teh Model.QueryCellInfo and Model.SaveCellInfo events to manage this behavior. > >The sample, Syncfusion\Essential Suite\Grid\Samples\DataBound\GDBGMultiHeader, has unbound columns that are managed through these events.

Administrator [Syncfusion]
Replied On January 23, 2004 12:51 PM UTC

As far as I know, there is no QueryCellInfo event in GridDataBoundGrid. It is a member of GridDataBoundGrid.Model. If I try to compile this code, this.gridDataBoundGrid1.QueryCellInfo += new GridQueryCellInfoEventHandler(grid_QueryCellInfo); I get this error. Syncfusion.Windows.Forms.Grid.GridDataBoundGrid'' does not contain a definition for ''QueryCellInfo Now GridControl does have a QueryCellInfo event, but GridDataBoundGrid does not.

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

;