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

RadGridView

1 Answer 57 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bindu
Top achievements
Rank 1
Bindu asked on 04 Sep 2014, 09:45 AM
Hello

I have urgent requirement,

I was using RadGridView in which i want to fetch data from XML and also need to add custom column Checkbox to enable/disable the row.

Using Winforms, WPF Telerik RadControls

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Sep 2014, 04:45 PM
Hello Bindu,

Thank you for writing.

Binding to XML is not directly supported by RadGridView but DataTables are supported and a DataSet (containing DataTables) can be created from an XML document. Please refer to our GridView >> Bind to XML help article which demonstrates how to load xml data in RadGridView. Additionally, you can add as many columns as you wish via the RadGridView.Columns collection. Thus, you can add GridViewCheckBoxColumn and disable/enable all the cells on the current row, except the current one. Here is a sample code snippet, demonstrating how to achieve it by using the RadGridView.ValueChanged event and the RadGridView.CellFormatting event:
 
public Form1()
{
    InitializeComponent();
 
    DataSet xmlDataSet = new DataSet();
    xmlDataSet.ReadXml(@"..\..\..\data.xml");
    this.radGridView1.DataSource = xmlDataSet.Tables[0];
 
    GridViewCheckBoxColumn checkBoxColumn = new GridViewCheckBoxColumn("Checked");
    radGridView1.MasterTemplate.Columns.Add(checkBoxColumn);
}
 
private void radGridView1_ValueChanged(object sender, EventArgs e)
{
    if (radGridView1.CurrentColumn is GridViewCheckBoxColumn)
    {
      radGridView1.EndEdit();
      radGridView1.CurrentRow.InvalidateRow();
    }
}
 
private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.Row is GridViewDataRowInfo && e.Row.Cells["Checked"].Value!=null)
    {
        var isChecked = e.Row.Cells["Checked"].Value ;
        if ((isChecked ==null ||(bool)isChecked==false)&& e.CellElement.ColumnInfo.Name!= "Checked")
        {
            e.CellElement.Enabled = false;
        }
        else
        {
            e.CellElement.Enabled = true;
        }
    }
}

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Bindu
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or