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

Filtering not work

1 Answer 203 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kim Johansen
Top achievements
Rank 1
Kim Johansen asked on 26 Jan 2010, 12:00 AM

Hi

I have my own objects I want to bind to my grid and I want to make the column by myself because it’s not all the fields I want publish so I do like this

            CompanyEOList Companylist = new CompanyEOList(WinXLFSecurity.XLFSecurity, WinXLFSecurity.CurrentDAL);  
            Companylist.GetAll();  
              
            gdCompanyList.MasterGridViewTemplate.AllowAddNewRow = false;  
            gdCompanyList.MasterGridViewTemplate.AutoGenerateColumns = true ;  
            gdCompanyList.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;  
 
gdCompanyList.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn("Address", "Address"));  
            gdCompanyList.DataSource = Companylist ;  
 

 

where gdCompanyList is my grid. When I do like this and want filtering I can’t edit the filtering textbox. If I set the property AutoGenerateColumns to true it works. I have also tried to set the property AllowFiltering on the new column but that work either.

            Telerik.WinControls.UI.GridViewDataColumn newColumn = new GridViewDataColumn("Name", "Name")

            newColumn.AllowFiltering = true;

            gdCompanyList.MasterGridViewTemplate.Columns.Add(newColumn);

 

What have I missing ?

One other thing. When I bind my own objects to the grid and the user is edit the objects how do I force the grid to save the change ?

Best regards
Kim Johansen

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 28 Jan 2010, 08:25 AM
Hello Kim Johansen,

If you want to create a custom column, you should create some of the columns listed in this documentation article. GridViewDataColumn and GridViewColumn classes should not be instantiated. They are basic classes for columns that you should not use. You may use the following code snippet in your case:

Company companyTelerik = new Company("Telerik", "Bulgaria");
Company companyMicrosoft = new Company("Microsoft", "USA");
 
List<Company> companies = new List<Company>();
companies.Add(companyTelerik);
companies.Add(companyMicrosoft);
 
radGridView.EnableFiltering = true;
radGridView.MasterGridViewTemplate.AutoGenerateColumns = false;
radGridView.MasterGridViewTemplate.AllowAddNewRow = false;
radGridView.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
 
radGridView.DataSource = companies;
 
GridViewTextBoxColumn txtColumn = new GridViewTextBoxColumn("MyUniqueName", "Address");
radGridView.MasterGridViewTemplate.Columns.Add(txtColumn);

When the user changes a value in specified field and the grid commits the changed in the object from its data source. If you want to commit the changes from your data source in the data base you can subscribe to CellEndEdit. Then you should save the changes of the current row in the data base using your data access layer API.

private void radGridView_CellEndEdit(object sender, GridViewCellEventArgs e)
{
    Company company = e.Row.DataBoundItem as Company;
    // TO DO: Save company object in data base
}

Let me know, if you need further assistance.

Best wishes,
Svett
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.
Tags
GridView
Asked by
Kim Johansen
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or