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
I use a method to add the 2 comboboxes to the risk child grid
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
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.
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.
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