i am new to telerik controls and winforms. I am using RadGridView, i want to do some calculations on each item data bound, is there any item data bound event i can capture and do some operation before binding it to gridview.
Thanks,
Sandeep
13 Answers, 1 is accepted
RadGridView does not implement ItemDataBound event. However, should you want to do calculations with the bound data, you can use the Expressions feature demonstrated in the Quick-Start Framework application (a.k.a. Examples), section RadGridView >> Expressions.
If you have additional questions, feel free to contact me.
Kind regards,
Nikolay
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Thanks for the reply.
i have business object Client, which has contactList. I created ClientList, which i want to bind with RadGridView as shown below. In the shown image there is text box, which should provide instant search. Is there any Telerik control, using which i can implement this functionality. Contact List showld be shown as dropdown list. This is an windows application.
If you have sample code to demonstrate this applicatio, it would be great.
Type Name to search client | |||
CheckBox | Client | Contact | |
|
Sandy | ContatcDropDownList | |
|
Andy | ContatcDropDownList |
Thanks,
Sandy
You can use the filtering operation of RadGridView for this scenario:
private ParameterValuePair parameter = null; |
private void searchTextBox_TextChanged(object sender, EventArgs e) |
{ |
if (parameter == null) |
{ |
this.radGridView1.EnableFiltering = true; |
this.radGridView1.MasterGridViewTemplate.ShowFilteringRow = false; |
parameter = new ParameterValuePair(GridFilterCellElement.ParameterName, searchTextBox.Text); |
FilterExpression filter = new FilterExpression(FilterExpression.BinaryOperation.AND, |
GridKnownFunction.StartsWith, GridFilterCellElement.ParameterName); |
filter.Parameters.Add(parameter); |
this.radGridView1.Columns["City"].Filter = filter; |
} |
else |
{ |
parameter.Value = searchTextBox.Text; |
} |
} |
I hope this helps.
Sincerely yours,
Julian Benkov
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Thanks for the reply. I got stuck at one more issue. i added GridViewCheckBoxColumn in the grid to and not binding any data column to this. i want to get checked property of the checkbox inside the column. how to retrive checked property of checkbox. i am trying to get this on ValueChanged event. here is the code i am using. is it possible to get true/ false status of checkbox.
private void radGridView1_ValueChanged(object sender, EventArgs e)
{
GridDataCellElement cell = sender as GridDataCellElement;
Telerik.WinControls.RadElement rootElement = cell.ElementTree.RootElement;
GridViewColumn gridViewColumn = cell.ColumnInfo;
object objectValue = cell.Value;
DataRowView drvHosts = (DataRowView) cell.RowInfo.DataBoundItem;
string clientName = drvHosts.Row[0].ToString();
}
Thanks & Regards,
Sandeep
You can use following code snippet to achieve your purpose:
private void radGridView1_ValueChanged(object sender, EventArgs e) |
{ |
GridDataCellElement cell = sender as GridDataCellElement; |
radGridView1.EndEdit(); |
if (cell is GridCheckBoxCellElement) |
{ |
MessageBox.Show(string.Format("The new value of checkbox is: {0}", (bool)cell.Value)); |
} |
} |
Julian Benkov
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I before upgrading to the latest version 2009.2.9.701, I was able to detect a grid checkbox change using ValueChanged event. I was able to cast the sender to a griddatacellelement to get column info. Now, with the latest release, the sender for my checkbox columns cannot be cast this type, and all of my code is now being bypassed. I didn't see this a "breaking change", but now I suspect I need to trap a differnent event? Thanks in advance for your reply.
private
void grdOpenTxn_ValueChanged(object sender, EventArgs e)
{
GridDataCellElement cell = sender as GridDataCellElement; <---This now comes back as null, it used to give data.
if (cell != null && ((GridViewDataColumn)cell.ColumnInfo).FieldName == "Selected")
{
if (grdOpenTxn.ActiveEditor is RadCheckBoxEditor)
In our latest release we did a major revamp of our editors system. This caused some changes. The ValueChanged event fires when the editor value is changed, in this case the sender argument is the editor itself. I modified your code to reflect the changes in our API. Here is the code:
void grdOpenTxn_ValueChanged(object sender, EventArgs e) |
{ |
RadCheckBoxEditor editor = sender as RadCheckBoxEditor; |
if (editor != null && ((GridViewDataColumn)this.grdOpenTxn.CurrentCell.ColumnInfo).FieldName == "Selected") |
{ |
//... |
} |
} |
I hope this helps. You can find more about events related to editors in RadGridView in the following help article. Should you have more questions, I will be glad to help.
Regards,
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.
Thank you for this question. Usually grids in WinForms applications commit their changes when the form closes or when an update button is pressed. Nevertheless, RadGridView supports various events which can be used to track that something has changed:
- The CellValueChanged event fires when a cell changes its value.
- The RowValidated event fires when changing the current row. You can use the IsModified property to track whether there is a cell which contains changes:
void
radGridView1_RowValidated(
object
sender, RowValidatedEventArgs e)
{
if
(e.Row.IsModified)
{
// ...
}
}
- The UserAddedRow and UserDeletedRow events fire when a row is added or removed by using the UI
I hope this helps.
Greetings,
Jack
the Telerik team
I want following gridview link functionality in windiws from gridview
http://demos.telerik.com/aspnet-ajax/grid/examples/overview/defaultcs.aspx
Thank you for writing.
Similar functionality is available in our Demo application >> GridView >> Rows >> Row Details example. It demonstrates a sample approach how to construct a detailed row look for your grid. Feel free to modify it on a way which suits your requirement best.
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
i am doing radgridview for winforms insert, update, delete but after updating record my grid is not taking updated value ,but in my datatable it is showing updated record here is following code i am using
string sQuery = "select id, ans1 as Answer1,ans2 as Answer2,ans3 as Answer3,ans4 as Answer4 from tblAnswer";
oDs = null;
oCon = new SqlConnection(conStr);
oCon.Open();
SqlCommand cmd = new SqlCommand(sQuery, oCon);
radTest.DataSource = null;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
radTest.DataSource = dt;
Thank you for writing back.
RadGridView is capable of fetching bindable properties and data. However, one important issue must be noted: during the data binding process, the grid extracts the data from the data source, but for any later changes in the data source, RadGridView should be notified.
According to the provided code snippet, you fill a DataTable with the current data in the database. Afterwards, the RadGridView.DataSource property is set to this DataTable. When a certain modification in the database is performed, it is not reflected to the DataTable. Hence, the RadGridView is not notified for any changes. You can fill the SqlDataAdapter with the new data and rebind the RadGridView ​in order to obtain the actual data.
I hope this information helps. If you have any additional questions, please let me know.
Regards,
Desislava
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.