I'm using the Q3 2007 V5 version.
thanks,
monirak
33 Answers, 1 is accepted
Thank you for contacting us.
Unfortunately, RadGridView doesn't support the RowAdding and the RowAdded events at this time. We will add such events in our upcoming release Q1 2008. I suggest using the ListChanged event of your currency manager.
When a value in some cell is changed, the ValueChanged event of the RadGridView is fired.
Let us know, if you have other questions.
All the best,
Jack
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
thanks,
Monirak
Thank you for this question.
The ValueChanged event is only fired when a value is changed. You should process this event, if you wish to track updates in RadGridView.
There is no specific event in RadGridView, that is fired when a row is inserted. As I mentioned in the previous post, we will correct this in our upcoming release Q1 2008. You can work around the issue by processing the ListChanged event. Refer to the code snippet below:
CurrencyManager manager = this.radGridView1.BindingContext[this.radGridView1.dataSource] as CurrencyManager; |
manager.ListChanged +=new ListChangedEventHandler(manager_ListChanged); |
void manager_ListChanged(object sender, ListChangedEventArgs e) |
{ |
if (e.ListChangedType == ListChangedType.ItemAdded) |
{ |
// ... |
} |
} |
I hope this helps. Do not hesitate to write me, if you need further assistance.
Best wishes,
Jack
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Thank you for getting back to us.
You should use the RowsChanging and RowsChanged events for this purpose. The Action property of the event arguments contains information whether the row was added or removed, and the NewItems array contains the affected rows.
Should you have any questions, I will gladly answer them.
All the best,
Jack
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Im having a similar problem when updating a radgridview value in a cell.
I'm using the latest package (WinForms Q3 2008). I set the grid to allow updating, it lets me change the value on the grid but when I check the db the value is not changed.
Do you have some code showing in VB how to change the values on the grid and post them back to the DB.
Thanks in advance
You should call the Update method of your table adapter. Consider the following code:
Me.employeesTableAdapter.Update(Me.nwindDataSet.Employees) |
I hope that helps. Do not hesitate to write us if you need further assistance.
Regards,
Jack
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Please try to access the row from the associated GridViewTemplate:
void
radGridView1_RowsChanged(
object
sender, GridViewCollectionChangedEventArgs e)
{
object
val = e.GridViewTemplate.Rows[e.NewStartingIndex].Cells[0].Value;
}
Greetings,
Julian Benkov
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.
I still didn't get it. After reading the above comments, i got a mess inside my head. I'm new to Telerik and Im using the trial version of Telerik Q1 2010.
Is there another way to add a new row into our DB using the "Click here to add a new row" and the CreateRow event? :"(
You can bind a DataTable object to RadGridView control. After that you can insert/edit/remove rows from the grid which will be automatically refreshed when bound to a DataTable object.
For database updates you must use the ADO.NET DataAdapter object. More information how to use ADO.NET objects for database operations you can find in this online tutorial.
Sincerely yours, Julian Benkov
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.
I answered my that question here.
http://social.msdn.microsoft.com/Forums/en/sqlce/thread/a4bae5d5-f8bb-44a9-921c-ea817193ae01
The changes which i make in the gridview, i want that to be reflected in the database table automatically or on a button click, which i could not so please help me and give me code for it in c#.
The database I am using is Sql.
Please view the answer in your next post.
Kind regards,Julian Benkov
the Telerik team
You can control adding, editing and deleting rows in the grid in the following way
this
.radGridView1.AllowEditRow =
false
;
this
.radGridView1.AllowAddNewRow =
true
;
this
.radGridView1.AllowDeleteRow =
false
;
this
.radGridView1.AddNewRowPosition = Telerik.WinControls.UI.SystemRowPosition.Top;
Hope that helps
Richard
Thanks. But I do not see how your code could help because it pertains to a whole row. I ihave a column Userid that is a primary key.
So when the user UPDATES, this Userid column should be read-only, and the user can change only the other columns.
When the user INSERTS, then NONE of the columns should be read-only.
John
To clarify, is this scenario correct?
1: For editing, you would like the Id column to be read only. The rest of the columns should be editable
2: When adding a new row, you would like all columns to be editable
Thanks
Richard
Hopefully, my summary was correct. If so, then here is a full exmaple that should help.
Designer File
partial
class
Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private
System.ComponentModel.IContainer components;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected
override
void
Dispose(
bool
disposing)
{
if
(disposing && (components !=
null
))
{
components.Dispose();
}
base
.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private
void
InitializeComponent()
{
this
.radGridView1 =
new
Telerik.WinControls.UI.RadGridView();
((System.ComponentModel.ISupportInitialize)(
this
.radGridView1)).BeginInit();
this
.SuspendLayout();
//
// radGridView1
//
this
.radGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this
.radGridView1.Location =
new
System.Drawing.Point(0, 0);
this
.radGridView1.Name =
"radGridView1"
;
this
.radGridView1.Size =
new
System.Drawing.Size(430, 300);
this
.radGridView1.TabIndex = 0;
this
.radGridView1.Text =
"radGridView1"
;
this
.radGridView1.CellClick +=
new
Telerik.WinControls.UI.GridViewCellEventHandler(
this
.radGridView1_CellClick);
//
// Form1
//
this
.AutoScaleDimensions =
new
System.Drawing.SizeF(6F, 13F);
this
.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this
.ClientSize =
new
System.Drawing.Size(430, 300);
this
.Controls.Add(
this
.radGridView1);
this
.Name =
"Form1"
;
this
.Text =
"Form1"
;
((System.ComponentModel.ISupportInitialize)(
this
.radGridView1)).EndInit();
this
.ResumeLayout(
false
);
}
#endregion
private
Telerik.WinControls.UI.RadGridView radGridView1;
}
Form1.cs
using
System.Collections.Generic;
using
System.Windows.Forms;
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
this
.radGridView1.AutoGenerateColumns =
true
;
List<Person> people =
new
List<Person>();
people.Add(
new
Person(
"Richard"
, 1));
this
.radGridView1.DataSource = people;
this
.radGridView1.Columns[
"Id"
].ReadOnly =
true
;
}
private
void
radGridView1_CellClick(
object
sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
if
(e.RowIndex == -1 && e.Column.Name ==
"Id"
)
{
this
.radGridView1.Columns[
"Id"
].ReadOnly =
false
;
}
else
{
this
.radGridView1.Columns[
"Id"
].ReadOnly =
true
;
}
}
}
public
class
Person
{
public
Person(
string
name,
int
id)
{
this
.Name = name;
this
.Id = id;
}
public
Person()
{
}
public
string
Name
{
get
;
set
; }
public
int
Id
{
get
;
set
; }
}
Hope that helps, but let me know if you have further questions
Richard
It seems this is a very common scenario, but it is not obvious how to do it, so your post will probably benefit many others.
John
Richard
this
.radGridView1.CellBeginEdit +=
new
Telerik.WinControls.UI.GridViewCellCancelEventHandler(
this
.radGridView1_CellBeginEdit);
private
void
radGridView1_CellBeginEdit(
object
sender, GridViewCellCancelEventArgs e)
{
if
(e.RowIndex > -1 && e.Column.Name ==
"Id"
)
{
e.Cancel =
true
;
}
}
Best regards,
Richard
John
Using WinForms, Q1, 2011
I am attempting the same solution, I have a load on Demand grid, master and child, the Child expands with data correctly, when i click on the Add New Row part, (or any where in the child for that matter), my RowIndex is always -1,
private void radGridView_CellBeginEdit_1(object sender, GridViewCellCancelEventArgs e)
{
if (e.RowIndex > -1 && e.Column.Name == "Barcode")
{
e.Cancel = true;
}
if (e.RowIndex > -1 && e.Column.Name == "Date")
{
e.Cancel = true;
}
}
Any assistance or guidance would be greatly appreciated
regards steve
This is correct behavior. The row index of these system rows (new row etc..) will be -1. Only the data rows will have a row index above -1.
Hope this helps but let me know if you need more information
Richard
Hi Richard,
thanks for the swift reply, my problem, I gather, is that it is unbound data, ie I build the Child Grid, Ie, the Data Rows are not linked to a database, would this explain why the RowIndex is -1, even when I click on one of the other (populated) rows? (see attached section of how i populate the child grid)
I need to somehow trigger your solution, but only on the new row, and not the already populated rows (if that makes sense)
Thnx, regards steve
private void radGridView_RowSourceNeeded(object sender, GridViewRowSourceNeededEventArgs e)
{
try
{
sps_BillableTableAdapter tblChildAdap = new sps_BillableTableAdapter();
String sCharge = e.ParentRow.Cells[1].Value.ToString();
Decimal nUnitCost = System.Convert.ToDecimal(e.ParentRow.Cells[3].Value);
tblChildAdap.Fill(dts_DWBillDataSet.sps_Billable, sCode, nPeriod, sCharge,nUnitCost);
DateTime dDate = new DateTime();
this.sDefCharge = e.ParentRow.Cells[1].Value.ToString(); //Set Master Val as default
this.sDefDesc = e.ParentRow.Cells[2].Value.ToString(); //Set Master Val as default
for (int i = 0; i < dts_DWBillDataSet.sps_Billable.Count; i++)
{
dts_DWBillDataSet.sps_BillableRow DataRow = dts_DWBillDataSet.sps_Billable[i];
GridViewRowInfo row = e.Template.Rows.NewRow();
row.Cells["Billable"].Value = DataRow["BillableID"];
row.Cells["SO"].Value = DataRow["SO"];
row.Cells["ChargeCode"].Value = DataRow["ChargeCode"];
row.Cells["Description"].Value = DataRow["Description"];
row.Cells["Barcode"].Value = DataRow["Barcode"];
row.Cells["Dept"].Value = DataRow["Dept"];
if (DataRow["Date"] != null)
{
dDate = System.Convert.ToDateTime(DataRow["Date"]);
row.Cells["Date"].Value = dDate;
} row.Cells["Site"].Value = DataRow["Site"];
row.Cells["Qty"].Value = DataRow["Qty"];
row.Cells["UnitCost"].Value = DataRow["UnitCost"];
row.Cells["TotalCost"].Value = DataRow["TotalCost"];
row.Cells["Charge"].Value = DataRow["Charge"];
row.Cells["Checked"].Value = DataRow["Checked"];
e.SourceCollection.Add(row);
}
tblChildAdap.Dispose();
this.InitialLoad = false;
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message, "Error Loading Transactions", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
In the Load-On-Demand scenario the RowIndex property is not synchronized with the source collection. For your needs in this scenario you can use ChildRows.IndexOf() method of GridViewTemplate or the parent GridViewRowInfo.
I hope this helps.
Kind regards,
the Telerik team
Thanks, just tried, could you please give a sample, as my attempt is still returning -1:
if (this.radGridView.MasterTemplate.ChildRows.IndexOf(e.Row) > -1)
Your assistance is much appreciated
thanks
regards
steve
Please open a new support ticket and send me a sample application that covers your scenario. This will allow me to review the API used and find the best solution for your case.
Thank you in advance.
Julian Benkov
the Telerik team
I have opened a new ticked, I have attached the Code that I use to Create the Master Child Grids as well as populate them, the Ticket Header is:
RowIndex always -1 using Unbound Grid
Thanks
Regards
Steve
Hi
I am using hierarchical rad grid view
and I adding Summary row and Adding new row in templates both of them an the bottom position
grid.Templates[0].AddNewRowPosition = SystemRowPosition.Bottom;
grid.MasterTemplate.Templates[0].SummaryRowsBottom.Add(new GridViewSummaryRowItem(new GridViewSummaryItem[]{
new GridViewSummaryItem("customerBankAccount_id", "{0:جمع }", GridAggregateFunction.Sum),
new GridViewSummaryItem("amountDetail", "{0}", GridAggregateFunction.Sum)
}));
grid.MasterTemplate.ShowTotals = true;
grid.MasterView.SummaryRows[0].PinPosition = PinnedRowPosition.Bottom;
both of them placed in bottom which in what I want.But the problem is the place of adding new row is at the bottom of summary row
which is not normal and I ewant to place summary row at the bottom ,under the adding row.Please let me to know, How can I solve this issue.
Thx
Best Regards,
Fariba
Thank you for writing.
RadGridView allows you to reorder only the system rows: GridFilterRowElement, GridSearchRowElement, GridNewRowElement. The summary rows are placed along with the data rows. If you need to have a summary row at the bottom and the new row to be above it, you can use a simple data row that is pinned to the bottom. However, in this case, it would be necessary to calculate programmatically the summary value by using the ViewCellFormatting event for example and setting the Text property of the cell element.
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik