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

Need a sample project of these codes!

19 Answers 243 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hamid
Top achievements
Rank 1
Hamid asked on 06 Sep 2012, 10:03 AM
Hi everybody
I confused about the following article.
http://www.telerik.com/help/winforms/gridview-editors-howto-allow-end-users-to-add-items-to-dropdownlisteditor.html 
Can someone give me a sample project of these codes?

19 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 06 Sep 2012, 12:27 PM
Hello Hamid,

Thank you for writing.

Generally speaking, we do not provide projects that second documentation articles and other support resources as we strive to make these resources as much helpful on their own as possible without the need of further assistance. Therefore, we would like to know what exactly do you find confusing about this article. We will address the part that you find difficult so that you and the others interested in the topic can find the article more useful.

Thank you for your cooperation. I am looking forward to your reply.

Regards,
Nikolay
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Hamid
Top achievements
Rank 1
answered on 06 Sep 2012, 04:51 PM
Thanks, but I really need a project!
For Example, in this article it's not mentioned where we must write these parts:
GridComboBoxCellElement cellElement = this.OwnerElement as GridComboBoxCellElement;
 
RadGridView grid = cellElement.GridControl;
AllowEnd_usersAddItemsComboBoxEditor f = (AllowEnd_usersAddItemsComboBoxEditor)grid.FindForm();
 
// Checking if the typed value exists in the datasource of the column.
NwindDataSet.CategoriesDataTable dt = f.DataSet.Categories;
for (int i = 0; i < dt.Rows.Count; i++)
{
    if (dt.Rows[i]["CategoryName"].ToString() == ((RadDropDownListEditorElement)this.EditorElement).Text)
    {
        return base.EndEdit();
    }
}
0
Nikolay
Telerik team
answered on 10 Sep 2012, 08:30 AM
Hi Hamid,

Please take a closer look at the following sentences in the documentation article just before the quoted code snippet:
Now it is time to create our custom editor. For the purposes of our goal, we need to create a class that derives from RadDropDownListEditor and override the EndEdit method. In this method, we first need to check whether the value typed by the user exists or not in the datasource of the GridViewComboBoxColumn. If it exists, we should terminate the execution of the EndEdit method.

In short, you should create a RadDropDownListEditor descendant class, override the EndEdit method and put the code snippet in question there. I would suggest that you name the descendant class CustomDropDownEditor. We will think of how we can improve the article to make this part more clear to the developer.

Let me know if you have additional questions.

Regards,
Nikolay
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Theo
Top achievements
Rank 2
answered on 18 Sep 2012, 08:15 AM
Hi Nikolay,

Svett referred me to this article. Please see my suggestions on how the article can be made more user friendly.
Thank you

http://www.telerik.com/account/support-tickets/view-ticket.aspx?threadid=605081 

0
Nikolay
Telerik team
answered on 18 Sep 2012, 08:36 AM
Hello Theo,

Thank you for your feedback.

I have already taken a look at it and some of the suggestions will be addressed shortly.

Let us know if you have additional feedback to share.

Regards,
Nikolay
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Theo
Top achievements
Rank 2
answered on 18 Sep 2012, 08:41 AM
Hi Hamid, Please see the attached code on how I implemented a solution for your problem. Hope it helps.

Scenario, I have a form called Tasks, it has a child grid where you can define risks regarding a task (1 task, many risks). I want my users to be able to use a drop down in the risk grid to, as they type, select an item already in the risks table, but only as look-up/auto-complete. A previous risk must not also be attached to a new task.

Start off by defining an additional new inherited class within my frmTasks form class file, outside of the frmTasks Class, but in the same file (you can move this out at a later stage, for now it might be easier to have all in the same file while testing.)
Public Class RiskDropDownEditor
    Inherits RadDropDownListEditor
 
    Public Overrides Function EndEdit() As Boolean
        Dim cellElement As GridComboBoxCellElement = TryCast(Me.OwnerElement, GridComboBoxCellElement)
 
        If cellElement.ColumnInfo.Name = "cboRiskDetail" Then
            ' Checking if the typed value exists in the datasource of the column.
            If frmTasks.CurrentRiskDetailList.Contains((CType(Me.EditorElement, RadDropDownListEditorElement)).Text) Then Return MyBase.EndEdit()
 
            ' We are adding new data in the underlying datasource of the combobox column
            frmTasks.CurrentRiskDetailList.Add((CType(Me.EditorElement, RadDropDownListEditorElement)).Text)
            cellElement.Tag = (CType(Me.EditorElement, RadDropDownListEditorElement)).Text
 
            Return MyBase.EndEdit()
        ElseIf cellElement.ColumnInfo.Name = "cboRiskMitigation" Then
            ' Checking if the typed value exists in the datasource of the column.
            If frmTasks.CurrentRiskMitigationList.Contains((CType(Me.EditorElement, RadDropDownListEditorElement)).Text) Then Return MyBase.EndEdit()
 
            ' We are adding new data in the underlying datasource of the combobox column
            frmTasks.CurrentRiskMitigationList.Add((CType(Me.EditorElement, RadDropDownListEditorElement)).Text)
            cellElement.Tag = (CType(Me.EditorElement, RadDropDownListEditorElement)).Text
 
            Return MyBase.EndEdit()
        End If
        Return MyBase.EndEdit()
    End Function
End Class
Notes: 
CurrentRiskDetailList and CurrentRiskMitigationList are both public shared variables in frmTasks defined as List(Of String). These 2 collections are populated from the database with a list of existing risk desc and mitigation desc

All of the following code is within the frmTasks form class
In the class body I define my 2 lookup lists and initialize them with all the existing string desc in the database
Public Shared CurrentRiskDetailList As List(Of String) = Risk.GetObjectSetRiskDetail
Public Shared CurrentRiskMitigationList As List(Of String) = Risk.GetObjectSetMitigation

I use a method to add the 2 comboboxes to the risk child grid
Public Sub AddCombosToGrid_Risks()
        If IsNothing(dgvRisks.Columns("cboRiskDetail")) Then
            Dim cboRisk As New GridViewComboBoxColumn
            With cboRisk
                .DataSource = CurrentRiskDetailList
                .HeaderText = "Detail"
                .FieldName = "RiskDetail"
                .Name = "cboRiskDetail"
                .DropDownStyle = RadDropDownStyle.DropDown
                .AutoCompleteMode = AutoCompleteMode.SuggestAppend
            End With
            dgvRisks.Columns.Add(cboRisk)
        End If
 
        If IsNothing(dgvRisks.Columns("cboRiskMitigation")) Then
            Dim cboRiskMitigation As New GridViewComboBoxColumn
            With cboRiskMitigation
                .DataSource = CurrentRiskMitigationList
                .HeaderText = "Mitigation"
                .FieldName = "Mitigation"
                .Name = "cboRiskMitigation"
                .DropDownStyle = RadDropDownStyle.DropDown
                .AutoCompleteMode = AutoCompleteMode.SuggestAppend
            End With
            dgvRisks.Columns.Add(cboRiskMitigation)
        End If
End Sub
Please Note that the combo datasources are the List(Of String) collections

Next I implement the EditorRequired event of the Risks grid to use the custom editor class
Private Sub dgvRisks_EditorRequired(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.EditorRequiredEventArgs) Handles dgvRisks.EditorRequired
    If (dgvRisks.CurrentColumn.Name = "cboRiskDetail") OrElse _
       (dgvRisks.CurrentColumn.Name = "cboRiskMitigation") Then
        If e.EditorType Is GetType(RadDropDownListEditor) Then
            e.Editor = New RiskDropDownEditor()
        End If
    End If
End Sub

Finally I implement the risks grid CellEndEdit event. This is needed to updated the selected item (cell display) correctly if you added a new item to the list, otherwise you might end up with a new item in the list, but nothing selected, which make it seem that the new item was not added.
Private Sub dgvRisks_CellEndEdit(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles dgvRisks.CellEndEdit
    If Not IsNothing(dgvRisks.CurrentRow) Then
        If e.Column.Name = "cboRiskDetail" Then
            If dgvRisks.CurrentCell.Tag IsNot Nothing Then
                dgvRisks.CurrentCell.Value = dgvRisks.CurrentCell.Tag
                dgvRisks.CurrentCell.Tag = Nothing
            End If
        ElseIf e.Column.Name = "cboRiskMitigation" Then
            If dgvRisks.CurrentCell.Tag IsNot Nothing Then
                dgvRisks.CurrentCell.Value = dgvRisks.CurrentCell.Tag
                dgvRisks.CurrentCell.Tag = Nothing
            End If
        End If
    End If
End Sub

EDIT:
When I reload/refresh my form after saving, you need to re-populate the 2 collections so that the new items are added from the database and the collections are up to date.
CurrentRiskDetailList = New List(Of String)
CurrentRiskDetailList = Risk.GetObjectSetRiskDetail
CurrentRiskMitigationList = New List(Of String)
CurrentRiskMitigationList = Risk.GetObjectSetMitigation
Risk.GetObjectSetRiskDetail and Risk.GetObjectSetMitigation are both functions in my BL classes that return a List(of String) using LinqToEntity

And that should be it, I hope I did not miss anything.
You did not mention if you are using C# or VB.NET so if you have trouble with the syntax, check out Telerik's code converter. 
http://converter.telerik.com/ 
Very cool tool that I use often and (no exaggeration) works 9 out of 10 times. It's only when you start using LINQ and variant datatypes that it sometimes does not correctly convert, which honestly is no biggy.

Let me know if you got this working and if it helped.
Happy Coding
Theo Jacobs
0
Abdul
Top achievements
Rank 1
answered on 07 Feb 2017, 04:26 AM

Hi Theo

I am doing a project using C#.And i am facing this problem(I want custom edit in RadGridViewComboBoxColumn).I converted this VB Code to C#,But it doesn't works.Can you help me please.Is there any other methods?

Thanks in advance.

Regards

ABDUL HAFEEL

0
Theo
Top achievements
Rank 2
answered on 07 Feb 2017, 08:01 AM

Hey there, attach your classes in a zip file of the C# implmentation as well as description what it is supposed to be doing.

Thx

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Feb 2017, 11:04 AM
Hello Abdul,

Thank you for writing.  

Feel free to use the online converter for converting from C# to VB and vice-versa:  http://converter.telerik.com/

Following the demonstrated approach in the referred help article, I have prepared a C# sample project for your reference: http://docs.telerik.com/devtools/winforms/gridview/editors/how-to/allow-end-users-to-add-items-to-dropdownlisteditor

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abdul
Top achievements
Rank 1
answered on 08 Feb 2017, 10:44 AM

Hi Dess,

Thank You Very Much.

I achieved this for 'GridViewComboBoxColumn'.This is my code snippet:

public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent();
        }
        //I want custom edit in both 'GridViewMultiComboBoxColumn' and 'GridViewComboBoxColumn'.
        DbTask mydbtas = new DbTask();
        public DataSet ds, ds1;
        public DataTable dt;
        public int RowIndex;
        #region BindProductDetails
        private void BindProductDetails()
        {
            string Query = "SELECT ProductID,ProductName FROM tblProduct";
            object[,] obj = new object[1, 2]
           {
                { "@quary_varc",Query},
               };
            ds = mydbtas.ExecuteQuery_SP("execute_simple_queries", obj);
            BindingSource productBS = new BindingSource();
            dt = ds.Tables[0];
            productBS.DataSource = dt;
            ((GridViewComboBoxColumn)radGridView1.Columns["clmProduct"]).DataSource = dt;
            //((GridViewMultiComboBoxColumn)radGridView1.Columns["clmProduct"]).ValueMember = "ProductID";
            ((GridViewComboBoxColumn)radGridView1.Columns["clmProduct"]).ValueMember = "ProductName";
            ((GridViewComboBoxColumn)radGridView1.Columns["clmProduct"]).DisplayMember = "ProductName";
        }
        #endregion BindProductDetails
        #region Binding Particulars
        public void BindingParticulars()
        {
            object[,] obj = new object[1, 2]
            {
                { "@quary_varc","SELECT DISTINCT particular FROM tblProductUnit"},
                };
            ds1 = mydbtas.ExecuteQuery_SP("execute_simple_queries", obj);
            BindingSource modelBS = new BindingSource();
            modelBS.DataSource = ds1.Tables[0];
            ((GridViewComboBoxColumn)radGridView1.Columns["clmParticulars"]).ValueMember = "Particulars";
            ((GridViewComboBoxColumn)radGridView1.Columns["clmParticulars"]).DisplayMember = "Particulars";
            ((GridViewComboBoxColumn)radGridView1.Columns["clmParticulars"]).DataSource = modelBS;
        }
        #endregion Binding Particulars
        private void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
        {
            if (e.EditorType == typeof(RadDropDownListEditor))
            {
                e.Editor = new CustomRadDropDownListEditor();
            }
        }
        private void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
        {
            RowIndex = Convert.ToInt32(e.RowIndex);
            if (radGridView1.Rows.Count - 1 == RowIndex)
            {
                if (radGridView1.CurrentCell.Value != null)
                    radGridView1.Rows.AddNew();
            }
            if (this.radGridView1.CurrentCell.Tag != null)
            {
                this.radGridView1.CurrentCell.Value = this.radGridView1.CurrentCell.Tag;
                this.radGridView1.CurrentCell.Tag = null;
            }
        }
        private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        {
            RowIndex = e.RowIndex;
        }
        private void RadForm1_Load(object sender, EventArgs e)
        {
            radGridView1.Rows.AddNew();
            BindProductDetails();
            BindingParticulars();
        }
    }
    public class CustomRadDropDownListEditor : RadDropDownListEditor
    {
        public override bool EndEdit()
        {
            GridComboBoxCellElement cellElement = this.OwnerElement as GridComboBoxCellElement;
            RadGridView grid = cellElement.GridControl;
            RadForm1 f = (RadForm1)grid.FindForm();
            DataTable dt = f.dt;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["ProductName"].ToString() == ((RadDropDownListEditorElement)this.EditorElement).Text)
                    return base.EndEdit();
            }
            f.radGridView1.CurrentRow.Cells["clmProduct"].Value = ((RadDropDownListEditorElement)this.EditorElement).Text;
            f.dt.Rows.Add(null, f.radGridView1.CurrentRow.Cells["clmProduct"].Value);
            return base.EndEdit();
        }
    }

Now I want this for 'GridViewMultiComboBoxColumn'.How can i achieve this for 'GridViewMultiComboBoxColumn'?

Thanks In Advance.

Regards

ABDUL HAFEEL

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Feb 2017, 11:15 AM
Hello Abdul, 

Thank you for writing back. 

I am glad that the provided sample project was useful for achieving your custom requirement. In order to achieve the same functionality for GridViewMultiComboBoxColumn, you can use a very similar approach. The important part is that the user typed value is added to the DataSource. However, in this case, instead of inheriting the RadDropDownListEditor, it is necessary to derive from RadMultiColumnComboBoxElement which is a derivative of BaseComboBoxElement.

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abdul
Top achievements
Rank 1
answered on 08 Feb 2017, 11:59 AM

Hi Dess,

Thanks For Your Time

I already tried this.Did'nt get OwnerElement and GridControl.And I used EditorElement instead of OwnerElement and EditorControl instead of GridControl,but it gives 'Telerik.WinControls.UI.MultiColumnComboGridView' instead of 'Telerik.WinControls.UI.RadGridView'.Is there anything wrong?

public class CustomRadMultiDropDownListEditor : RadMultiColumnComboBoxElement
    {
        public override bool EndEdit()
        {
            RadMultiColumnComboBoxElement cellElement = this.OwnerElement as RadMultiColumnComboBoxElement;//did'nt get OwnerElement.
            RadGridView grid = cellElement.GridControl;
            RadForm1 f = (RadForm1)grid.FindForm();
            DataTable dt = f.dt;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["ProductName"].ToString() == ((RadMultiColumnComboBoxElement)this.EditorElement).Text)
                    return base.EndEdit();
            }
            f.radGridView1.CurrentRow.Cells["clmProduct"].Value = ((RadMultiColumnComboBoxElement)this.EditorElement).Text;
            f.dt.Rows.Add(null, f.radGridView1.CurrentRow.Cells["clmProduct"].Value);
            return base.EndEdit();
        }
    }

Thanks In Advance

Regards

ABDUL HAFEEL

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Feb 2017, 02:56 PM
Hello Abdul, 

Thank you for writing back. 

The GridComboBoxCellElement can be access by the RadMultiColumnComboBoxElement.Parent property. Here is a sample code snippet:
GridViewMultiComboBoxColumn mccb = new GridViewMultiComboBoxColumn();
mccb.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown;
mccb.DataSource = this.categoriesBindingSource;
mccb.DisplayMember = "CategoryName";
mccb.ValueMember = "CategoryID";
mccb.FieldName = "CategoryID";
this.radGridView1.Columns.Add(mccb);

private void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
{
    if (e.EditorType == typeof(RadDropDownListEditor))
    {
        e.Editor = new CustomRadDropDownListEditor();
    }
    else if (e.EditorType == typeof(RadMultiColumnComboBoxElement))
    {
        e.Editor = new CustomRadMultiColumnComboBoxElement();
    }
}


public class CustomRadMultiColumnComboBoxElement : RadMultiColumnComboBoxElement
{
    protected override Type ThemeEffectiveType    
    {
        get   
        {
            return typeof(RadMultiColumnComboBoxElement);    
        }
    }
 
    public override bool EndEdit()
    {
        GridComboBoxCellElement cellElement = this.Parent as GridComboBoxCellElement;//did'nt get OwnerElement.
        RadGridView grid = cellElement.GridControl;
        RadForm1 f = (RadForm1)grid.FindForm();
        // Checking if the typed value exists in the datasource of the column.
        NorthwindDataSet.CategoriesDataTable dt = f.DataSet.Categories;
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (dt.Rows[i]["CategoryName"].ToString() == this.Text)
            {
                return base.EndEdit();
            }
        }
        // An example of what we can do when we enter the custom text.
        // In this case we are adding a new data row in the underlying datasource of
        // the combobox column and then in the CellEndEdit we are setting
        // the ID value of the newly created row to RadGridView.
        NorthwindDataSet.CategoriesRow newCategoriesRow = dt.NewCategoriesRow();
        newCategoriesRow.CategoryName = this.Text;
        f.DataSet.Categories.Rows.Add(newCategoriesRow);
        // Updating the database. You can do it here at another place
        // you find suitable for this purpose, for example, on FormClosing.
        f.CategoriesTA.Update(f.DataSet.Categories);
        cellElement.Tag = newCategoriesRow.CategoryID;
        return base.EndEdit();
    }
}

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abdul
Top achievements
Rank 1
answered on 09 Feb 2017, 12:35 PM

Hi Dess,

Thanks For Your Time

This is working fine when we set GridViewMultiComboBoxColumn.DataSource to common GridViewMultiComboBoxColumn.But in my case,set GridViewMultiComboBoxColumn.DataSource to GridViewMultiComboBoxColumn according to previous GridViewComboBoxColumn.ie;Each RadGridViewRow has different DataSources.In this case I can't set the GridViewComboBoxColumn.DataSource to a collection that contains all units in FormLoad(Because in my original project it contains lots of data and i don't need DisplayMember(ValueMember is enough)).

public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent();
        }
        DbTask mydbtas = new DbTask();
        public DataTable dt;
        private void RadForm1_Load(object sender, EventArgs e)
        {
            radGridView1.Rows.AddNew();
            BindProductDetails();
        }
        #region BindProductDetails
        private void BindProductDetails()
        {
            string Query = "SELECT ProductID,ProductName FROM tblProduct";
            object[,] obj = new object[1, 2]
           {
                { "@quary_varc",Query},
               };
            DataSet ds = mydbtas.ExecuteQuery_SP("execute_simple_queries", obj);
            BindingSource productBS = new BindingSource();
            productBS.DataSource = ds.Tables[0];
            ((GridViewComboBoxColumn)radGridView1.Columns["clmProduct"]).DataSource = ds.Tables[0];
            ((GridViewComboBoxColumn)radGridView1.Columns["clmProduct"]).ValueMember = "ProductID";
            ((GridViewComboBoxColumn)radGridView1.Columns["clmProduct"]).DisplayMember="ProductName";
        }
        #endregion BindProductDetails
        public DataSet SelectUnitsByProduct(int ProductID)
        {
            object[,] obj = new object[1, 2]
            {
                 { "@product_Id",ProductID},
            };
            DataSet Units = mydbtas.ExecuteQuery_SP("select_units_by_product", obj);
            return Units;
        }
        private void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
        {
            int rowIndex = Convert.ToInt32(e.RowIndex);
            if (radGridView1.Rows.Count - 1 == rowIndex)
            {
                if (radGridView1.CurrentCell.Value != null)
                    radGridView1.Rows.AddNew();
            }
        }
        private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        {
            if (this.radGridView1.CurrentColumn.Name == "clmUnit")
            {
                RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)this.radGridView1.ActiveEditor;
                RadMultiColumnComboBoxElement editorElement = (RadMultiColumnComboBoxElement)editor.EditorElement;
                DataSet ds = SelectUnitsByProduct(Convert.ToInt32(this.radGridView1.CurrentRow.Cells["clmProduct"].Value));
                BindingSource productBS = new BindingSource();
                dt = ds.Tables[0];
                productBS.DataSource = dt;
                editorElement.DataSource = productBS;
                editorElement.ValueMember = "UnitID";
                editorElement.DisplayMember = "UnitID";
                editorElement.SelectedValue = null;
                //editorElement.SelectedValue = this.radGridView1.CurrentCell.Value;
            }
        }
        private void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
        {
            if (e.EditorType == typeof(RadMultiColumnComboBoxElement))
                e.Editor = new CustomRadMultiDropDownListEditor();
        }
    }
    public class CustomRadMultiDropDownListEditor : RadMultiColumnComboBoxElement
    {
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadMultiColumnComboBoxElement);
            }
        }
        public override bool EndEdit()
        {
            GridComboBoxCellElement cellElement = this.Parent as GridComboBoxCellElement;
            RadGridView grid = cellElement.GridControl;
            RadForm1 f = (RadForm1)grid.FindForm();
            DataTable dt = f.dt;
            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["UnitID"].ToString() == ((RadMultiColumnComboBoxElement)this.EditorElement).Text)
                        return base.EndEdit();
                }
                f.radGridView1.CurrentRow.Cells["clmUnit"].Value = ((RadMultiColumnComboBoxElement)this.EditorElement).Text;
                f.dt.Rows.Add(f.radGridView1.CurrentRow.Cells["clmUnit"].Value, f.radGridView1.CurrentRow.Cells["clmUnit"].Value);
                //I got the value in DataTable 'f.dt' also in 'f.radGridView1.CurrentRow.Cells["clmUnit"].Value'.But When Leaving From Cell,it disappears.
            }
            return base.EndEdit();
        }
    }

 

Hope you understand my problem.

Here I am attaching two images.In [Pic3],i manually typed some text.In [Pic4],leaving from cell,typed text disappeared.

Thanks In Advance

Regards

ABDUL HAFEEL

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 09 Feb 2017, 02:37 PM
Hello Abdul, 

Thank you for writing back. 

According to the provided information, I suppose that you are trying to achieve cascading combo boxes. The following KnowledgeBase article demonstrates a approach for different source collections per row in a GridViewComboBoxColumn considering another value on the row: http://www.telerik.com/support/kb/winforms/gridview/details/cascading-comboboxes-in-radgridview

This approach can be followed for GridViewMultiComboBoxColumn as well. The important thing, in this case, is that the GridViewMultiComboBoxColumn.DataSource collection must contain all available options in order to store the cell's values. However, in the RadGridView.CellEditorInitialized event you should specify the RadMultiColumnComboBoxElement.DataSource property to a subset of the whole GridViewMultiComboBoxColumn.DataSource collection considering another cell's value on the same row.

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abdul
Top achievements
Rank 1
answered on 09 Feb 2017, 03:54 PM

Hi Dess,

Thanks Again

I know cascading comboboxes in RadGridView and also custom edit in GridViewMultiComboBoxColumn.But now I want to know how these two properties achieve together,in same GridViewMultiComboBoxColumn.

Hope you understand my question.

Regards

ABDUL HAFEEL

0
Hristo
Telerik team
answered on 10 Feb 2017, 02:48 PM
Hello Abdul,

Thank you for writing.

As my colleague stated you can follow the approach as demonstrated in the KB article. Can you please elaborate what is not clear so that I can help you?

Please let me know if you need further assistance.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abdul
Top achievements
Rank 1
answered on 11 Feb 2017, 11:14 AM

Hi Hristo,

Thank you for your time.

I have a GridViewComboBoxColumn and GridViewMultiComboBoxColumn namely,'clmProduct' and 'clmUnitRate' respectively.I set DataSources to 'clmUnitRate' according to 'clmProduct'.(Here each product has its own RetailRate,MRP,SpecialRate,etc..So in this case,i can't set whole set into 'clmUnitRate' because it contains lots of data[for example,a shop has thousands of products and each product has its own different rates]).Here i set the DataSource to 'clmUnitRate' in RadGridView.CellEditorInitialized event.So Cascading ComboBoxes is fine(here GridViewMultiComboBoxColumn.ValueMember and GridViewMultiComboBoxColumn.DisplayMember are set to same value(rates)).Now i want custom edit in GridViewMultiComboBoxColumn(clmUnitRate).If Cascading ComboBoxes is not in use,Custom Edit in GridViewMultiComboBoxColumn is fine.

My Problem here that,I can't get both (Cascading ComboBoxes  and Custom Edit) together in GridViewMultiComboBoxColumn.

Hope you got my problem.And i am attaching here the code snippet:

public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent();
        }
        DbTask mydbtas = new DbTask();
        public DataTable dt;
        private void RadForm1_Load(object sender, EventArgs e)
        {
            radGridView1.Rows.AddNew();
            BindProductDetails();
        }
        #region BindProductDetails
        private void BindProductDetails()
        {
            string Query = "SELECT ProductID,ProductName FROM tblProduct";
            object[,] obj = new object[1, 2]
           {
                { "@quary_varc",Query},
               };
            DataSet ds = mydbtas.ExecuteQuery_SP("execute_simple_queries", obj);
            BindingSource productBS = new BindingSource();
            productBS.DataSource = ds.Tables[0];
            ((GridViewComboBoxColumn)radGridView1.Columns["clmProduct"]).DataSource = ds.Tables[0];
            ((GridViewComboBoxColumn)radGridView1.Columns["clmProduct"]).ValueMember = "ProductID";
            ((GridViewComboBoxColumn)radGridView1.Columns["clmProduct"]).DisplayMember="ProductName";
        }
        #endregion BindProductDetails
        public DataSet SelectUnitsByProduct(int ProductID)
        {
            object[,] obj = new object[1, 2]
            {
                 { "@product_Id",ProductID},
            };
            DataSet Units = mydbtas.ExecuteQuery_SP("select_units_by_product", obj);
            return Units;
        }
        private void radGridView1_CellEndEdit(object sender, GridViewCellEventArgs e)
        {
            int rowIndex = Convert.ToInt32(e.RowIndex);
            if (radGridView1.Rows.Count - 1 == rowIndex)
            {
                if (radGridView1.CurrentCell.Value != null)
                    radGridView1.Rows.AddNew();
            }
        }
        private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        {
            if (this.radGridView1.CurrentColumn.Name == "clmUnitRate")
            {
                RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)this.radGridView1.ActiveEditor;
                RadMultiColumnComboBoxElement editorElement = (RadMultiColumnComboBoxElement)editor.EditorElement;
                DataSet ds = SelectUnitsByProduct(Convert.ToInt32(this.radGridView1.CurrentRow.Cells["clmProduct"].Value));
                BindingSource productBS = new BindingSource();
                dt = ds.Tables[0];
                productBS.DataSource = dt;
                editorElement.DataSource = productBS;
                editorElement.ValueMember = "UnitRate";
                editorElement.DisplayMember = "UnitRate";
                editorElement.SelectedValue = null;
                //editorElement.SelectedValue = this.radGridView1.CurrentCell.Value;
            }
        }
        private void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
        {
            if (e.EditorType == typeof(RadMultiColumnComboBoxElement))
                e.Editor = new CustomRadMultiDropDownListEditor();
        }
    }
    public class CustomRadMultiDropDownListEditor : RadMultiColumnComboBoxElement
    {
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadMultiColumnComboBoxElement);
            }
        }
        public override bool EndEdit()
        {
            GridComboBoxCellElement cellElement = this.Parent as GridComboBoxCellElement;
            RadGridView grid = cellElement.GridControl;
            RadForm1 f = (RadForm1)grid.FindForm();
            DataTable dt = f.dt;
            if (dt != null)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["UnitRate"].ToString() == ((RadMultiColumnComboBoxElement)this.EditorElement).Text)
                        return base.EndEdit();
                }
                f.radGridView1.CurrentRow.Cells["clmUnitRate"].Value = ((RadMultiColumnComboBoxElement)this.EditorElement).Text;
                f.dt.Rows.Add(f.radGridView1.CurrentRow.Cells["clmUnitRate"].Value, f.radGridView1.CurrentRow.Cells["clmUnitRate"].Value);
                //I got the value in DataTable 'f.dt' also in 'f.radGridView1.CurrentRow.Cells["clmUnit"].Value'.But When Leaving From Cell,it disappears.
            }
            return base.EndEdit();
        }
    }

I need cascading as well as custom edit in same GridViewMultiComboBoxColumn.

Regards,

ABDUL HAFEEL

0
Hristo
Telerik team
answered on 13 Feb 2017, 06:02 PM
Hi Hamid,

Thank you for writing back.

The provided code snippets appear to be correct. Please note, however, that I cannot run them nor test them locally due to the specifics of your application.

In order to fully understand your scenario and current task please open up a support ticket and send us your project along with some sample data to be run locally.

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Hamid
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Hamid
Top achievements
Rank 1
Theo
Top achievements
Rank 2
Abdul
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Hristo
Telerik team
Share this question
or