GridViewComboBoxColumn select index when form load

1 Answer 156 Views
ComboBox and ListBox (obsolete as of Q2 2010) GridView
ebrahim
Top achievements
Rank 1
Iron
Iron
ebrahim asked on 21 Jan 2022, 02:25 PM | edited on 22 Jan 2022, 06:00 AM

hi

my code is


void BindGridDeviceName() { string select = "SELECT * from Device;"; using (IDbConnection connection = new SqlConnection(DataLayer.ConnectionClass.ConnectionDaynamic.GetConnectionString)) { var list = connection.ExecuteReader(select); DataTable dt = new DataTable(); dt.Load(list); ((GridViewComboBoxColumn)radGridViewService.Columns["DeviceName"]).DataSource = dt; ((GridViewComboBoxColumn)radGridViewService.Columns["DeviceName"]).DisplayMember= "DeviceName"; ((GridViewComboBoxColumn)radGridViewService.Columns["DeviceName"]).ValueMember = "Id"; } }

 

 

------------------------------------

I want when my form is loaded
  The first item or ID from the combo box for each row is in select(show)

I do not want to be displayed by clicking on cells

like combobox.SelectedIndex

2-how to get value cValueMember = "Id" to insert database

thank


1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Feb 2022, 01:42 PM
Hello, Ebrahim,   

According to the provided code snippet, it seems that a GridViewComboBoxColumn is added to RadGridView. It is not clear whether the grid is bound to a DataSource collection or used in unbound mode. But if you need to have some data loaded in the grid cells after loading, you need to ensure that the data cells in RadGridView are filled with data:

A. Bound scenario - If there is a field from the applied RadGridView.DataSource that can be matched to the values (GridViewComboBoxColumn.ValueMember values) from the GridViewComboBoxColumn, feel free to set the GridViewComboBoxColumn.FieldName property to the respective field from the RadGridView.DataSource collection. Otherwise, you can use the Unbound scenario.

B. Unbound scenario - Iterate the RadGridView.Rows collection and set the Value property for the data cell belonging to this GridViewComboBoxColumn to the first value from the GridViewComboBoxColumn.DataSource collection, e.g. the first SupplierID if the column's ValueMember is set to "SupplierID"

More information how to setup the GridViewComboBoxColumn is available here:
https://docs.telerik.com/devtools/winforms/controls/gridview/columns/column-types/gridviewcomboboxcolumn 

I am not sure that I understand your second question: "2-how to get value cValueMember = "Id" to insert database". Could you please give us more details about the exact requirement that you are trying to achieve? Once we get better understanding of the precise case, we would be able to think about a suitable solution and provide further assistance. Thank you in advance.

I am looking forward to your reply.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

ebrahim
Top achievements
Rank 1
Iron
Iron
commented on 04 Feb 2022, 06:55 AM

Hello, thank you. I found the answer to my questions before your answer thanks again
Tags
ComboBox and ListBox (obsolete as of Q2 2010) GridView
Asked by
ebrahim
Top achievements
Rank 1
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or