This is a migrated thread and some comments may be shown as answers.

Issues with DefaultValuesNeeded event

3 Answers 234 Views
GridView
This is a migrated thread and some comments may be shown as answers.
newUserTlk
Top achievements
Rank 1
newUserTlk asked on 03 Jun 2014, 06:07 PM
On adding new row in RadGridView, I am assigning DefaultValues in DefaultValuesNeeded event. When I start typing in the new row, the default values appear but the moment I hit enter on the row ( so that it is added to the current grid ) , all the default values just disappear.
I have created columns dynamically.

Please tell me what is the issue or am I missing anything ?

Below is my code.

grid code:

private void BindGrid()
        {
 
            this.ExportSettingGridView.AllowAddNewRow = false;
            this.ExportSettingGridView.AutoGenerateColumns = false;
            this.ExportSettingGridView.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
 
            this.ExportSettingGridView.ShowGroupPanel = false;
            this.ExportSettingGridView.MasterTemplate.EnableGrouping = false;
            this.ExportSettingGridView.EnableHotTracking = true;
 
            //Settings Name column
            GridViewTextBoxColumn nameCol = new GridViewTextBoxColumn();
            nameCol.FieldName = "Name";
            nameCol.Name = "Name";
            nameCol.HeaderText = "Export Setting";
            this.ExportSettingGridView.Columns.Add(nameCol);
 
            //Settings Na Option Combo Box
            GridViewComboBoxColumn naDataOptionCol = new GridViewComboBoxColumn();
            naDataOptionCol.FieldName = "NaData.NaDataOption";
            naDataOptionCol.Name = "NaData.NaDataOption";
            naDataOptionCol.HeaderText = "NA Data Option";
            naDataOptionCol.DataSource = Enum.GetValues(typeof(NADataOption));
            naDataOptionCol.DataType = typeof(NADataOption);
            naDataOptionCol.DataSourceNullValue = NADataOption.BLANKROW;       
            this.ExportSettingGridView.Columns.Add(naDataOptionCol);
 
            //Setting NA Option Custom Text field Columns
            GridViewTextBoxColumn naDataOptionCustomCol = new GridViewTextBoxColumn();
            naDataOptionCustomCol.FieldName = "NaData.Custom";
            naDataOptionCustomCol.Name = "NaData.Custom";
            naDataOptionCustomCol.HeaderText = "NA Data Option Custom";
            this.ExportSettingGridView.Columns.Add(naDataOptionCustomCol);
 
            //Setting IncludePartialLastPeriod
            GridViewComboBoxColumn includePartialLastPeriodCol = new GridViewComboBoxColumn();
            includePartialLastPeriodCol.FieldName = "IncludePartialLastPeriod";
            includePartialLastPeriodCol.HeaderText = "Include Partial Last Period";
            includePartialLastPeriodCol.Name = "IncludePartialLastPeriod";
            includePartialLastPeriodCol.DataSource = new String[] { "True", "False" };
            includePartialLastPeriodCol.DataType = typeof(bool);
            this.ExportSettingGridView.Columns.Add(includePartialLastPeriodCol);
 
            //Setting Sorting Column
            GridViewComboBoxColumn sortingCol = new GridViewComboBoxColumn();
            sortingCol.FieldName = "Sorting";
            sortingCol.HeaderText = "Sorting";
            sortingCol.Name = "Sorting";
            sortingCol.DataSource = new String[] { "ASC", "DESC" };
            this.ExportSettingGridView.Columns.Add(sortingCol);
 
            //Setting Data Load Position
            GridViewComboBoxColumn dataPostionOptionsCol = new GridViewComboBoxColumn();
            dataPostionOptionsCol.FieldName = "DataLoadPosition.CursorLocation";
            dataPostionOptionsCol.Name = "DataLoadPosition.CursorLocation";
            dataPostionOptionsCol.HeaderText = "Cursor Location";
            dataPostionOptionsCol.DataSource = new String[] { "True", "False" };
            dataPostionOptionsCol.DataType = typeof(bool);
            dataPostionOptionsCol.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList;
            this.ExportSettingGridView.Columns.Add(dataPostionOptionsCol);
 
            //Setting Data Load Cell location
            GridViewTextBoxColumn cellCol = new GridViewTextBoxColumn();
            cellCol.FieldName = "DataLoadPosition.Cell";
            cellCol.Name = "DataLoadPosition.Cell";
            cellCol.HeaderText = "Cell Location";
            this.ExportSettingGridView.Columns.Add(cellCol);
 
            this.ExportSettingGridView.BestFitColumns();
        }
          private void newButton_Click(object sender, EventArgs e)
          {
            this.ExportSettingGridView.AllowAddNewRow = !this.ExportSettingGridView.AllowAddNewRow;
          }

        private void ExportSettingGridView_DefaultValuesNeeded(object sender, GridViewRowEventArgs e)
        {
            if (e.Row != null && e.Row is GridViewNewRowInfo)
            {
                e.Row.Cells["NaData.NaDataOption"].Value = currentProfile.NaData.NaDataOption;
                e.Row.Cells["NaData.Custom"].Value = currentProfile.NaData.Custom;
                e.Row.Cells["DataLoadPosition.CursorLocation"].Value = currentProfile.DataLoadPosition.CursorLocation;
                e.Row.Cells["DataLoadPosition.Cell"].Value = currentProfile.DataLoadPosition.Cell;
            }
        }


3 Answers, 1 is accepted

Sort by
0
newUserTlk
Top achievements
Rank 1
answered on 03 Jun 2014, 07:20 PM
NaData.NaDataOption column is a comboxbox of enums. The value ( right hand side ) currentProfile.NaData.NaDataOption is a enum. But Could it be that I cannot set the combobox value like so? Is there any other way, like extracting the editor and using that or something ?
0
newUserTlk
Top achievements
Rank 1
answered on 04 Jun 2014, 04:29 PM
Please ignore not using this event anymore.
0
George
Telerik team
answered on 06 Jun 2014, 12:00 PM
Hi Sonam,

Thank you for writing.

Just to clarify the scenario at hand in case someone stumbles upon this thread.

When you click a cell and its column is GridViewComboBoxColumn you are initializing a drop down editor. When a value from the editor is chosen it is applied to the Value property of the cell, however the values of the editor itself come from the DataSource property of the column. This means that you should either change the DataSource of the property or subscribe to the CellEditorInitialized event and change the items in the current editor. For the other editors the approach with the DefaultValuesNeeded event will work since they take their starting value from the Value of the cell.

Let me know, should you have further questions.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
newUserTlk
Top achievements
Rank 1
Answers by
newUserTlk
Top achievements
Rank 1
George
Telerik team
Share this question
or