3 Answers, 1 is accepted
0
Hi Rajesh,
I am not sure if I understand this question correctly. You can set a default value when adding a new row by processing the DefaultValuesNeeded event. Consider the following code snippet:
If your column contains null values, you could specify a default value when opening e new editor. This can be done through processing the CellBeginEdit event. Here is a sample:
I hope this helps. If you have any questions, do not hesitate to write me back.
Best wishes,
Jack
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.
I am not sure if I understand this question correctly. You can set a default value when adding a new row by processing the DefaultValuesNeeded event. Consider the following code snippet:
void radGridView1_DefaultValuesNeeded(object sender, GridViewRowEventArgs e) |
{ |
e.Row.Cells["Value1"].Value = 1; |
} |
If your column contains null values, you could specify a default value when opening e new editor. This can be done through processing the CellBeginEdit event. Here is a sample:
void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) |
{ |
if (e.ColumnIndex == 0) |
{ |
RadComboBoxEditor editor = (RadComboBoxEditor)this.radGridView1.ActiveEditor; |
editor.SelectedIndex = 0; |
} |
} |
I hope this helps. If you have any questions, do not hesitate to write me back.
Best wishes,
Jack
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
rajesh
Top achievements
Rank 2
answered on 17 Feb 2009, 02:34 PM
Hi Jack,
Thanks for your reply.
I have a requirement like first i am binding a datatable to the datasource of the rad grid and then i m assignina a new set of values for the GridviewLookUpColumn as in the given code.so now i need to show a default value in this column.
the event defaultvaluesneeded isnt firing even
GridViewLookUpColumn gvLookup1 = (GridViewLookUpColumn)radgrid1.Columns["Reason"];
gvLookup1.HeaderText = "Reason";
gvLookup1.FieldName = "Reason";
gvLookup1.DataSource = ds.Tables[1];
gvLookup1.DisplayMember = "EMPName";
gvLookup1.ValueMember = "EMPCode";
gvLookup1.Width = 160;
radgrid1.AutoScroll = true;
can you please help me in this regard.
Thanks
Rajesh
Thanks for your reply.
I have a requirement like first i am binding a datatable to the datasource of the rad grid and then i m assignina a new set of values for the GridviewLookUpColumn as in the given code.so now i need to show a default value in this column.
the event defaultvaluesneeded isnt firing even
GridViewLookUpColumn gvLookup1 = (GridViewLookUpColumn)radgrid1.Columns["Reason"];
gvLookup1.HeaderText = "Reason";
gvLookup1.FieldName = "Reason";
gvLookup1.DataSource = ds.Tables[1];
gvLookup1.DisplayMember = "EMPName";
gvLookup1.ValueMember = "EMPCode";
gvLookup1.Width = 160;
radgrid1.AutoScroll = true;
can you please help me in this regard.
Thanks
Rajesh
0
Hi rajesh,
The DefaultValuesNeeded event is fired only when adding a new row.
You can set cell values at any time by iterating through the Rows collection. Here is a sample:
You can also set the a default text when there is no value in the cell. This can be done when processing the CellFormatting event. Take a look at the code snippet below:
Please, tell me if I misunderstood your question and if you need any further assistance.
All the best,
Jack
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.
The DefaultValuesNeeded event is fired only when adding a new row.
You can set cell values at any time by iterating through the Rows collection. Here is a sample:
foreach (GridViewDataRowInfo row in this.radGridView1.Rows) |
{ |
row.Cells["Value1"].Value = 10; |
} |
You can also set the a default text when there is no value in the cell. This can be done when processing the CellFormatting event. Take a look at the code snippet below:
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) |
{ |
if (e.CellElement.ColumnInfo.HeaderText == "Value1") |
{ |
GridDataCellElement dataCell = e.CellElement as GridDataCellElement; |
if (dataCell != null) |
{ |
if (dataCell.Value == null || dataCell.Value == DBNull.Value) |
{ |
dataCell.Text = "null"; |
} |
} |
} |
} |
Please, tell me if I misunderstood your question and if you need any further assistance.
All the best,
Jack
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.