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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Proglem getting "ValueMember" value from a ComboBox field in GDBG

Thread ID:

Created:

Updated:

Platform:

Replies:

17058 Jul 29,2004 04:00 PM UTC Aug 2,2004 10:06 AM UTC WinForms 7
loading
Tags: GridControl
Gil Kalo
Asked On July 29, 2004 04:00 PM UTC

Hi, I''m trying to get the value of a combo box cell in a grid data bound grid. In a grid I''m defining several columns and the first one is a column binded to a field. After the first time a value is selected, and the record is left, I''m making the following call: gdbg.GetViewStyleInfo( e.RowIndex, binder.NameToColIndex("FIELD_NAME")).CellValue And I''m getting the valueMember value, and this is ok. The problem is, on the second time I''m entering this record, if I''m making the same call, now I''m getting the displayMember value???? Why is it??? I always want to get the valueMember value! How can I access the control valuemember value and not the display value? I know it''s possible to do it via the renderer. But I found the renderer property only in the "CurrentCell" property return value. I even tried to change the current cell position by calling : gdbg.CurrentCell.SetCurrentCellNoActivate(e.RowIndex, binder.NameToColIndex("FIELD_NAME")). The position has changed, but the values are of the last active cell. So I tried to call the renderer gdbg.CurrentCell.Renderer.UpdateControlValue(), but it didn''t help also! I''m really frustrated, How can I get the combo valueMember field at any time, even if it''s not the current cell? Thanks in advance, Gil

Administrator [Syncfusion]
Replied On July 29, 2004 04:08 PM UTC

When ths cell is not actively being edited, you should be able to get the value member using; Dim val as object = gdbg(rowIndex, binder.NameToColIndex("FIELD_NAME")).CellValue But if the cell is being edited, then the above code would give you the old value member, and not the currently editing value. Does this not work for you?

Gil Kalo
Replied On August 1, 2004 04:05 AM UTC

Obivously, I tried to make this trivial call, but this doesn''t work for me all the time. >When ths cell is not actively being edited, you should be able to get the value member using; > >Dim val as object = gdbg(rowIndex, binder.NameToColIndex("FIELD_NAME")).CellValue > > >But if the cell is being edited, then the above code would give you the old value member, and not the currently editing value. > >Does this not work for you? > >

Administrator [Syncfusion]
Replied On August 1, 2004 05:46 AM UTC

Sorry for asking obvious questions. Here is a sample that seems to work as expected for me using version 2.0.5.1. What are you doing differently? Does it work for you? ComboBoxGDBG_861.zip

Gil Kalo
Replied On August 1, 2004 03:00 PM UTC

Hi Clay, I tried your sample and it worked fine, but it seems to me that we are doing different things. I''m using the "RootHierarchyLevel" and a typed data set. For example look at the following code: GridHierarchyLevel hlRoot = gdbg1.Binder.RootHierarchyLevel; hlRoot.LayoutColumns( new string[] { "f1","f2","f3","f4","f5"}); //Now I''m trying to configure the combo column hlRoot.GridBoundColumns["f1"].HeaderText = "fieldHeader"; GridStyleInfo fieldNameStyle = hlRoot.GridBoundColumns["f1"].StyleInfo; fieldNameStyle.CellType = "ComboBox" fieldNameStyle.DataSource = "SomeTableInATypedDataSet"; fieldNameStyle.CellValueType = typeof(int); //Value member is defined as int in the typed data set fieldNameStyle.DisplayMember = "Field1"; fieldNameStyle.ValueMember = "Field2"; Now, somehow I''m getting the cell value as a string, even though the value field is int. Defining the "CellValueType" as int doesn''t seems to help?! P.S, I can''t get the cell value using the row\colum indexer, I''m getting "object ''gdbg1'' doesn''t have an indexer"?! Does calling "gdbg1.GetViewStyleInfo(e.RowIndex, binder.NameToColIndex(FIELD_FIELD_NAME)).CellValue" is differenct than using the indexer? Any ideas? Thanks Gil >Sorry for asking obvious questions. > >Here is a sample that seems to work as expected for me using version 2.0.5.1. What are you doing differently? > >Does it work for you? > >ComboBoxGDBG_861.zip > >

Administrator [Syncfusion]
Replied On August 1, 2004 04:08 PM UTC

I added this code at the bottom of the Form_Load in the sample instead of using the InternalColumn to get the style, and it still seems to work. GridHierarchyLevel hlRoot = gridDataBoundGrid1.Binder.RootHierarchyLevel; hlRoot.LayoutColumns(new string[] { "Col2","Col0","combo"}); GridStyleInfo style = hlRoot.GridBoundColumns["combo"].StyleInfo; style.CellType = "ComboBox"; style.DataSource = dt; style.DisplayMember = "displayMem"; style.ValueMember = "valueMem"; Exactly what is the type of gdbg1? If you are getting that no indexer error, then I suspect it is typed as a GridControlBase. You would need to either cast it as a GridDataBoundGrid to use the indexer, or use gdbg1.Model and index that. But I do not think it will make a difference as using GetCellStyleInfo worked for me in the sample. Exactly where are you trying to use this code? (You reference e.RowIndex which suggests it might be in some event. This might be playing a role in the problem depending upon the event.) If you can post a sample showing the problem, we can try to spot something here.

Gil Kalo
Replied On August 2, 2004 08:23 AM UTC

Clay, I found a problem in my code which probably causes this problem. After setting the data source for the column, in the row save event I''m calling select on that data source. the next time I query the value of this combo cell, I don''t get the value member, but the formatted text?! I fixed it by creating a data set only for the combo. But, I found another problem in the same matter: I attached to this message your sample with minor changes: 1. The combo column type is changed to string(In my project I''m working with a typed data set and the field type is string) 2. On RowSave event I''m querying the cell value. The results are, when selecting a value from the combo using the mouse, and moving to the next record, the "ValueMember" is returned as a string. When selecting the "ValueMember" using the keyboard (select with arrows and enter) and after that move with the keyboard to the next record, the value is retrived as an int32?! Why is that? Thanks, Gil >I added this code at the bottom of the Form_Load in the sample instead of using the InternalColumn to get the style, and it still seems to work. > >GridHierarchyLevel hlRoot = gridDataBoundGrid1.Binder.RootHierarchyLevel; >hlRoot.LayoutColumns(new string[] { "Col2","Col0","combo"}); >GridStyleInfo style = hlRoot.GridBoundColumns["combo"].StyleInfo; >style.CellType = "ComboBox"; >style.DataSource = dt; >style.DisplayMember = "displayMem"; >style.ValueMember = "valueMem"; > > >Exactly what is the type of gdbg1? If you are getting that no indexer error, then I suspect it is typed as a GridControlBase. You would need to either cast it as a GridDataBoundGrid to use the indexer, or use gdbg1.Model and index that. > >But I do not think it will make a difference as using GetCellStyleInfo worked for me in the sample. > >Exactly where are you trying to use this code? (You reference e.RowIndex which suggests it might be in some event. This might be playing a role in the problem depending upon the event.) > >If you can post a sample showing the problem, we can try to spot something here. ReplayComboBoxGDBG_7714.zip

Administrator [Syncfusion]
Replied On August 2, 2004 10:06 AM UTC

I think the reason you are seeing this casting error in the modified sample is that the type in the combobox datasource is still int. And, when the values set in both DataTables, the values are also ints. So, you can avoid the problem in the sample by changing everything used in the column to string. Or, another way is to just retrieve style.Text instead of style.CellValue in RowSaved.

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

;