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

Combo box inside GridView

9 Answers 333 Views
GridView
This is a migrated thread and some comments may be shown as answers.
yaqub
Top achievements
Rank 2
yaqub asked on 11 Aug 2009, 10:43 AM
Hi,

I need your help to use GridViewComboBoxColumn inside RadGridView.

1:     Please guide me how can i access the GridViewComboBoxColumn in RadGridView_CellFormatting Event.

2:    How can i get the GridViewComboBoxColumn when processing each row of the grid?

Thanks.

9 Answers, 1 is accepted

Sort by
0
lkeel
Top achievements
Rank 1
answered on 11 Aug 2009, 03:19 PM
I have recently had to do just this, so here is what I found.  Please note I am not a Telerik team member so this may not be the absolute best solution, but it is what I got to work for me...

In answer to #1:
(NOTE: In this case the unique name for the column that has my checkbox is "enabled")
if (this.grid.Columns[e.CellElement.ColumnIndex].UniqueName == "enabled")
{
((RadCheckBoxEditorElement) e.CellElement.Children[0]).Checked = Telerik.WinControls.Enumerations.ToggleState.On;
}


In answer to #2:
If you are just trying to find the rows that are checked, then here is a linq statement that I wrote:
(NOTE: In this case the unique name for the column that has my checkbox is "enabled")
List<GridViewDataRowInfo> selectedRows = new List<GridViewDataRowInfo>(from selRow in this.grid.Rows
                                                                                   where ((RadCheckBoxEditorElement)selRow.Cells["enabled"].CellElement.Children[0]).CheckState == Telerik.WinControls.Enumerations.ToggleState.On
                                                                                   orderby this.grid.Rows.IndexOf(selRow)
                                                                                   select selRow );


If you are trying to loop through all the rows then:
foreach (GridViewRowInfo row in this.grid.Rows)
{
                   checked = ((RadCheckBoxEditorElement) row.Cells["enabled"].CellElement.Children[0].CheckState == Telerik.WinControls.Enumerations.ToggleState.On;
}


Hope this helps...
Lee
0
Victor
Telerik team
answered on 14 Aug 2009, 09:10 AM
Hello Yaqub,

Thank you for writing. You can check in CellFormatting if the column that the arguments point to is a GridViewComboBox column. Here is how the event handler for CellFormatting should look like:

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)  
{  
    if (this.radGridView1.Columns[e.CellElement.ColumnIndex] is GridViewComboBoxColumn)  
    {  
        // Do necessarry tasks.  
    }  

When iterating over the rows you can do this:

foreach(GridViewRowInfo row in this.radGridView1.Rows)  
{  
    // Loop through the cells only if you do not know the indices of your combo box columns.  
    foreach (GridViewCellInfo cell in row.Cells)  
    {  
        if (this.radGridView1.Columns[cell.ColumnInfo.Index] is GridViewComboBoxColumn)  
        {   
            // Do necessary tasks.  
        }  
    }  

Write again if you have other questions.

Greetings,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
yaqub
Top achievements
Rank 2
answered on 14 Aug 2009, 09:28 AM
Hi,
This is helpful!
Thanks.
0
SachinC
Top achievements
Rank 1
answered on 19 Sep 2010, 08:19 AM
HI,

i have added combobxocolumn in raggridview programatically and given a datasource to it.

Private Sub AddUserSignOffColumn()
  
Dim ddlUserSignoffColumn As New GridViewComboBoxColumn
  
With ddlUserSignoffColumn
  
.HeaderText = "User SignOff"
  
.DisplayMember = "UserName"
  
.ValueMember = "UserID"
  
.FieldName = "ChecklistSignoffUser"
  
.Name = "ChecklistSignoffUser"
  
.Width = 110
  
.AllowFiltering = False
  
.AllowGroup = False
  
.AllowHide = False
  
.AllowResize = False
  
.AllowSort = False
  
.DropDownStyle = RadDropDownStyle.DropDownList
  
.AutoCompleteMode = AutoCompleteMode.SuggestAppend
  
ddlUserSignoffColumn.DataSource = dtUsers
  
End With
  
gridViewHome.MasterTemplate.Columns.Insert(11, ddlUserSignoffColumn)
  
End Sub

when the grid view is displayed currently its showing blank by default. when i click on comboboxcell then dropdownlist is displayed.
what i want to do is that,
if the "ChecklistSignoffUser" value is null in database i want to display value as "Select User" from datasource and if the
id is present then by defult the username must be displayed.

how to change the selected value of comboboxcolum  in cellformating event?

Thanks
0
Martin Vasilev
Telerik team
answered on 22 Sep 2010, 08:42 PM
Hi Sachin,

To achieve the described functionality, you should use combo-box column's NullValue property:
Dim ddlUserSignoffColumn As New GridViewComboBoxColumn   
ddlUserSignoffColumn.NullValue = "Select User"

I hope this helps. Let me know if you have other questions.

Sincerely yours,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Randa
Top achievements
Rank 1
answered on 19 Dec 2011, 04:49 PM
What if I want to display the selected Value of a RadDropDownList in a GridviewComboBoxColumn?
0
Ivan Petrov
Telerik team
answered on 22 Dec 2011, 11:27 AM
Hello Randa,

Thank you for writing.

Can you please explain what you want to achieve in greater detail as I do not fully understand your requirement. In addition, add the version of the control you are using as this thread is very old and it is discussing a very old version.

I am looking forward to your reply.

All the best,
Ivan Petrov
the Telerik teamQ3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Babison
Top achievements
Rank 1
answered on 09 Jan 2012, 05:45 AM
i hav a radmulticolumncombobox in datagrid and i want filtering in that case how i can do that???
0
Ivan Petrov
Telerik team
answered on 11 Jan 2012, 06:28 PM
Hello Babison,

Thank you for writing.

Currently the RadMultiColumnComboBox editor in the RadGridView does not have filtering functionality available. We will consider it when we plan our future releases if other users ask for it.

Should you need other help, feel free to write back.

Greetings,
Ivan Petrov
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Tags
GridView
Asked by
yaqub
Top achievements
Rank 2
Answers by
lkeel
Top achievements
Rank 1
Victor
Telerik team
yaqub
Top achievements
Rank 2
SachinC
Top achievements
Rank 1
Martin Vasilev
Telerik team
Randa
Top achievements
Rank 1
Ivan Petrov
Telerik team
Babison
Top achievements
Rank 1
Share this question
or