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. Image for the cookie policy date

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

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

7 Replies

AD Administrator Syncfusion Team 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?


GK Gil Kalo 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? > >


AD Administrator Syncfusion Team 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


GK Gil Kalo 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 > >


AD Administrator Syncfusion Team 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.


GK Gil Kalo 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


AD Administrator Syncfusion Team 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.

Loader.
Live Chat Icon For mobile
Up arrow icon