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

Add new Row in GridView

17 Answers 720 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bruce Lam
Top achievements
Rank 1
Bruce Lam asked on 08 Sep 2009, 06:35 AM
When i choose allow add new row in RadGridView. Now i want to add Combobox in to row. How can i do that? Please help me as impossible as. if you have example in C# please give me. Thanks

17 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 08 Sep 2009, 08:43 AM
Hi lam,

You should add a GridViewComboBoxColumn in RadGridView. Here is a sample code snippet:

List<Item> items = new List<Item>(); 
items.Add(new Item(0, "zero")); 
items.Add(new Item(1, "one")); 
items.Add(new Item(2, "two")); 
items.Add(new Item(3, "three")); 
items.Add(new Item(4, "four")); 
 
GridViewComboBoxColumn combo = new GridViewComboBoxColumn("Product"""); 
combo.DataType = typeof(int); 
combo.DataSource = items; 
combo.DisplayMember = "Name"
combo.ValueMember = "ID"
this.radGridView1.Columns.Add(combo); 

Should you have any further questions, don't hesitate to ask.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Bruce Lam
Top achievements
Rank 1
answered on 08 Sep 2009, 09:22 AM
Thanks Jack for helping me. and i have one more question about combobox in RadGridView how can i auto complete data in Combobox. I has tried but i cannot. Please help me.Thanks alot.
0
Jack
Telerik team
answered on 09 Sep 2009, 12:40 PM
Hi lam,

Currently there is an issue when using combobox column with auto-complete. When using auto-complete to select the value, the cell value is not updated. We are working on this issue and it will be addressed in our upcoming release. You can turn the feature on when handling the CellEditorInitialized event:

void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e) 
    RadComboBoxEditor editor = this.radGridView1.ActiveEditor as RadComboBoxEditor; 
    if (editor != null
    { 
        RadComboBoxEditorElement editorElement = (RadComboBoxEditorElement)editor.EditorElement; 
        editorElement.AutoCompleteMode = AutoCompleteMode.SuggestAppend; 
        editorElement.DropDownStyle = RadDropDownStyle.DropDown; 
    } 

Should you have any other questions, we will be glad to help.

Regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Bruce Lam
Top achievements
Rank 1
answered on 10 Sep 2009, 09:51 AM
Thanks Jack for helping me. I want to validate new row When i add new row. But I cannot do that. I have used CellVatidating but it just validate just one cell . I want to when i input all cells it will be insert into but when i just input some cells and click enter it not validate some cells empty and it's also insert normally. Please help me to validate all cells , just insert into database when all field is inputed.
0
Jack
Telerik team
answered on 10 Sep 2009, 03:30 PM
Hello lam,

You should use the RowValidating event in this case. Use the DataRowInfo property of GridViewNewRowInfo to get the actual cell values:

void radGridView1_RowValidating(object sender, RowValidatingEventArgs e) 
    if (e.Row is GridViewNewRowInfo) 
    { 
        GridViewDataRowInfo dataRowInfo = (GridViewDataRowInfo)((GridViewNewRowInfo)e.Row).DataRowInfo; 
        if (dataRowInfo != null && dataRowInfo.Cells[0].Value == DBNull.Value || dataRowInfo.Cells[0].Value == null
        { 
            e.Cancel = true
        } 
    } 

We are aware that the API is a bit confusing and we plan to improve it in one of our upcoming releases. Don't hesitate to write us, If you have any other questions.

 
Regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Bruce Lam
Top achievements
Rank 1
answered on 11 Sep 2009, 04:00 AM
Thanks for helping me I add GridViewComboBoxColumn in RadGridView when i add new record i cannot get valueMember of this Combobox i just get DisplayMember and FieldName. How can i get valueMember. and how can i recognize what GridViewComboboxColumn is belong to this column, when i use event cellformating to format this gridviewCoboboxColumn but when i change this it change all other GridViewComboboxColumn.
0
Jack
Telerik team
answered on 11 Sep 2009, 09:54 AM
Hello lam,

I am not sure that I understand your question correctly. ValueMember is a property of GridViewComboBoxColumn. The Columns collection in RadGridView is of type GridViewDataColumn and maybe this cause the confusion. You should cast the desired column to GridViewComboBoxColumn type:

string valueMember = ((GridViewComboBoxColumn)this.radGridView1.Columns[1]).ValueMember; 

And yes, when you change any property of the column, it affects all cells that belong to this column. Please, specify more details about what is your intention. I will be glad to assist you further.

Best wishes,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Bruce Lam
Top achievements
Rank 1
answered on 12 Sep 2009, 01:58 AM
Hi Jack How can i catch event click to add new Row . because when i input all data for one row and afterthat i move mouse out and it add new row to grid but cannot add into database. Please help me
0
Jack
Telerik team
answered on 14 Sep 2009, 02:44 PM
Hello lam,

The best practice in this case is to update the database when closing the form or when clicking on dedicated Update button. When using a table adapter, you can call its Update method. However, you can handle RowValidated event in this case. Here is a sample:

void radGridView1_RowValidated(object sender, RowValidatedEventArgs e) 
    if (e.Row is GridViewNewRowInfo) 
    { 
        GridViewDataRowInfo newRowInfo = (GridViewDataRowInfo)((GridViewNewRowInfo)e.Row).DataRowInfo; 
        //... 
    } 

newRowInfo contains all entered values except for the CurrentColumn. The value of the CurrentColumn can be accessed by using the ActiveEditor.Value property. I admit, that this is a little bit complicated. We will provide a more convenient API in one of our upcoming releases.

I hope this helps. If you have any questions, please don't hesitate to ask.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
steve
Top achievements
Rank 1
answered on 08 Nov 2011, 12:19 AM
if (!(e.Row is GridViewNewRowInfo)) return;

With the new release 2011.2.11.831, adding rows pragmatically changed.  When I clicked on the "Click here to add a new row", Row no longer is of type GridViewNewInfo and the cells don't open up for editing. Is there a new event I should use to get the data from the new row after it is created?

  



0
Jack
Telerik team
answered on 10 Nov 2011, 11:15 AM
Hello Steve,

Since 2009 we changed the new row behavior to be more like MS DataGridView behavior. Now the actual data row is created when the validation process finishes or more exactly when the CellValidated event is processed. Now you can use GridViewNewRowInfo cell value directly. However, you can switch back to the old behavior by setting the AddNewBoundRowBeforeEdit property to true:
this.radGridView1.MasterTemplate.AddNewBoundRowBeforeEdit = true;

I am not sure about the exact scenario and that is why I would ask you to send me your application. I will research the case and I will try to find the best option.

I am looking forward to your reply.
 
Best wishes,
Jack
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
steve
Top achievements
Rank 1
answered on 10 Nov 2011, 04:37 PM
Thanks Jack.  I will try that this afternoon and if I cannot get it to work I will upload my code, well a sample project.

Stephen
0
Jack
Telerik team
answered on 14 Nov 2011, 01:38 PM
Hi Steve,

Thank you for the update. I am looking forward to your reply. If you have any other questions, do not hesitate to contact us.
 
All the best,
Jack
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
steve
Top achievements
Rank 1
answered on 14 Nov 2011, 04:43 PM
The issue ended up being that I was never setting the BeginEdit property.  I am assuming that the older version this was automatically set when adding a new row.  Now I have to treat the new row like a edit and it works just fine. Thanks.
0
Jack
Telerik team
answered on 17 Nov 2011, 03:42 PM
Hi Steve,

I am glad to hear that the issue is solved now. If you have any other questions, please do not hesitate to contact us.
 
Regards,
Jack
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Muthu
Top achievements
Rank 1
answered on 07 Nov 2012, 06:58 AM
Hi,
   I have  a GridViewComboBoxColumn column and my value member is int field and display member is string column and my DropDownStyle is DropDown. When I come to the GridViewComboBoxColumn column through tab my focus will be there. Note that cursor will not blink inside the cell. But cell is selected. In this time If I press a  letter ex. 'A', it has to show me records only which has 'A'. But it is giving object reference error. Pl find image attached.

How to solver that. I want to give filter option. Help me.
0
Jack
Telerik team
answered on 07 Nov 2012, 01:47 PM
Hi Muthu,

I was not able to reproduce the described issue using our latest release - Q3 2012. Maybe there is something specific in your application. Please, open a new support ticket and send us your project. This will allow us to investigate the issue in detail and provide you with a proper solution.

I am looking forward to your project.
 
Greetings,
Jack
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
GridView
Asked by
Bruce Lam
Top achievements
Rank 1
Answers by
Jack
Telerik team
Bruce Lam
Top achievements
Rank 1
steve
Top achievements
Rank 1
Muthu
Top achievements
Rank 1
Share this question
or