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

Winform RadGridview data binding events

13 Answers 811 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sandeep
Top achievements
Rank 1
Sandeep asked on 30 Jul 2008, 05:42 PM
hi,
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

Sort by
0
Nikolay
Telerik team
answered on 01 Aug 2008, 02:59 PM
Hi Sandeep,

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.
0
Sandeep
Top achievements
Rank 1
answered on 01 Aug 2008, 04:39 PM
Hi Nikolay,
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


0
Julian Benkov
Telerik team
answered on 04 Aug 2008, 09:23 AM
Hi Sandeep,

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.
Don't hesitate to contact us if you have other questions.

Sincerely yours,
Julian Benkov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Sandeep
Top achievements
Rank 1
answered on 08 Aug 2008, 05:40 PM
hi,
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
0
Julian Benkov
Telerik team
answered on 11 Aug 2008, 09:19 AM
Hi 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)); 
    } 

Don't hesitate to contact us if you have other questions.

All the best,
Julian Benkov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Elizabeth
Top achievements
Rank 1
answered on 22 Jul 2009, 04:33 PM
Hi -

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)

 

0
Jack
Telerik team
answered on 23 Jul 2009, 10:24 AM
Hi Elizabeth,

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.
0
Bryan Ruddy
Top achievements
Rank 2
answered on 30 Jul 2010, 09:40 PM
I am trying to find the event that is executed whenever a peice of data is modified in a RadGridView.  Subsequently I am trying to update the data source but cannot find the appropriate event for this.
0
Jack
Telerik team
answered on 03 Aug 2010, 09:25 PM
Hello Bryan Ruddy,

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
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
0
SATISH
Top achievements
Rank 1
answered on 17 Oct 2014, 11:47 AM
hello ,
I want following gridview link  functionality in windiws from gridview
http://demos.telerik.com/aspnet-ajax/grid/examples/overview/defaultcs.aspx
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Oct 2014, 02:36 PM
Hello Satish,

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.

 
0
SATISH
Top achievements
Rank 1
answered on 25 Nov 2014, 12:53 PM
Hi 
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;






0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 28 Nov 2014, 09:42 AM
Hello Satish,

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.

 
Tags
GridView
Asked by
Sandeep
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Sandeep
Top achievements
Rank 1
Julian Benkov
Telerik team
Elizabeth
Top achievements
Rank 1
Jack
Telerik team
Bryan Ruddy
Top achievements
Rank 2
SATISH
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or