We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GridControl and GridDataControl

I am not sure why there are 2 wpf grid controls in syncfusion products and I don't know their relation ship. Maybe GridDataControl contains GridControl?

Anyway, here are 2 issues I have.

1, I was using GridDataControl because I need to binding the control to ObservableCollection object, then I realized when I set a column GridDataColumnStyle CellType as CheckBox, the user need to double click the cell to get into edit mode and then click to change the checkbox value, that's 3 clicks to change a boolean value.

So I noticed the one using GridControl in your example, user can click once in each cell and edit value immediately, that's exactly what I want, but the problem is, I can not bind my collection object to this GridControl.

Can you help on this please?

2, How do I set the grid column type to be non-editable ComboBox when I need to use data binding? For non-editable I mean either exclusive or autocomplete option.

Thanks.

15 Replies

RI richard October 8, 2009 10:08 PM UTC

3, While using Databinding, as rows growing, how to make the grid automatically scroll to the bottom so the last row is always visible?


GK Ganesan K Syncfusion Team October 9, 2009 07:11 AM UTC

Hi Richard,

Thanks for using Syncfusion products.

GridDataControl uses the GridControl internally. Using GridDataControl you can bind the dataSources directly.

For #1, You need to set the following properties in GridDataControl XAML declaration,

UpdateMode="PropertyChanged"
ActivateCurrentCellBehavior="ClickOnCell"

This will update the changes when clicking the cell as well as update it to the underlying record.

Download the workaround sample in the below location and check it out.
http://www.syncfusion.com/uploads/redirect.aspx?file=sample_442d9b2e.zip&team=development

For #2, You can use the DropDownStyle enumerator for this. It has three values: Editable, Exclusive, AutoComplete. Default value is Editable.

You can use the following code for changing to Exclusive or AutoComplete mode.









For #3, You can use the ScrollToBottom method in GridControlBase for scroll to bottom.

For #2 and #3 you can download the workaround sample from the below location.
http://www.syncfusion.com/uploads/redirect.aspx?file=GDCSample_6f047b27.zip&team=development


Please let me know if you need any more details.

Thanks
Ganesan


RI richard October 9, 2009 02:58 PM UTC

Thanks, that's very fast response. It's almost perfect.

For #3, how do I catch the new row inserted event for the GridDataControl itself?

What I want to do is in the View code:

void dataGrid_NewRowDataInserted(object sender, EventArgs e)
{
foreach (GridControlBase grid in dataGrid.Model.Views)
{
grid.ScrollToBottom();
}
}

So when I want to add new row, I just need to modify the ViewModel.


GK Ganesan K Syncfusion Team October 12, 2009 03:39 PM UTC

Hi Richard,

Thanks for the feedback.

You can listen the Model.View.CollectionChanged event like below

dataGrid.Model.View.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(View_CollectionChanged);


void View_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
dataGrid.Model.View.Refresh();
foreach (GridControlBase grid in dataGrid.Model.Views)
{
grid.ScrollToBottom();
}
}
Please let me know if you need any more details.

Thanks
Ganesan


RI richard October 12, 2009 04:08 PM UTC

Thanks.

I found dataGrid.Model.Views but I can not find dataGrid.Model.View, so the following did not compile:

dataGrid.Model.View.Fresh();

as well as:

dataGrid.Model.View.CollectionChanged

I tried to search GridControl and GridDataControl for reference of the "View" but did not get any hint.


GK Ganesan K Syncfusion Team October 13, 2009 04:57 AM UTC

Hi Richard,

Thanks for the details. dataGrid.Model.View is only avail in our latest build.

We have added new Grouping model in our latest build. Please download the latest build 7.4.0.9 from the below location.

www.syncfusion.com/downloads/development-builds

We also have made a small API changes listing, If you are using anything from this list please refer to the document below,

http://www.syncfusion.com/uploads/redirect.aspx?file=apichanges_3645b05c.doc&team=development

We also fixed some issues regarding in our latest build. If you want this fixed binaries then create the support Incident, we will update you with the Patch file.

Let us know if you need any more details.

Thanks
Ganesan


RI richard October 14, 2009 08:41 PM UTC

Hi, I tried the new version but found too many data binding bugs. While I am waiting for your bug fixing, is there anyway to catch this CollectionChanged event using version 7.3.0.20?


CB Clay Burch Syncfusion Team October 15, 2009 08:33 AM UTC

What is the type of your ItemsSource? Is it an IBindingList object, or a DataTable, or an ObservableCollection, or a CollectionView or something else?

Depending upon what the ItemsSource is, then may be an event on the ItemsSource that allows you to catch changes. This event would not be dependent on any particular Syncfusion version.


CB Clay Burch Syncfusion Team October 15, 2009 09:13 AM UTC

I noticed in your original post, you said you were using a ObservableCollection. Here is a little sample that will always scroll to the bottom after entering a new row from the UI using an observale collection. It uses the grid.Model.RowsInserted event to scroll the last row into view.




WpfApplication26_583fd7b1.zip


RI richard October 19, 2009 08:45 PM UTC

well, that works pretty good, however, I can only get one-way data binding work, I saw the data source got updated when user click and edited the cell value, but when I change the ObservableCollection ViewModel value, the corresponding cell did not get updated. Is there a way I can set the binding mode to be "Two-way"?

My ViewModel is like this:

gridDataControl1.ItemsSource = m_Sales;

public class Sales : ObservableCollection
{
}

public class Record : INotifyPropertyChanged
{
public double Data2
{
get { return m_nData2; }
set {
m_nData2 = value;
if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Data2"));
}
}
}


CB Clay Burch Syncfusion Team October 20, 2009 08:11 AM UTC

Make sure these two properties are set on the GridDataControl.

UpdateMode="PropertyChanged" NotifyPropertyChanges="True"


RI richard October 20, 2009 03:21 PM UTC

well, do you have a solution of NotifyPropertyChanges="True" for version 7.3.0.20?


CB Clay Burch Syncfusion Team October 20, 2009 04:25 PM UTC

You can try this. Listen to the CollectionChanged on your ObservableCollection.

m_Sales.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(m_Sales_CollectionChanged);


Then in the handler, refresh the grid.

void Window1_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
foreach (GridControlBase grid in gridDataControl1.Model.Views)
{
grid.InvalidateCells();
}
}


This is not optimal code, but I think will work in 7.3.0.20. Using 7.4 with its new properties would be better.


RI richard October 21, 2009 06:58 PM UTC

This does not work if I change the individual field value, it might only work if I add/delete row data.

And also we are using the MVVD model, we want to seperate the ViewModel from the View, so we want the event to be catched and handled within the View only.

I tried the new version 7.4.0.9 for the 2-way data binding and can not make it working. I sent the incident ticket update 2 days ago, can you please check it out? 61066


GK Ganesan K Syncfusion Team October 22, 2009 10:46 AM UTC

Hi Richard,

We have updated the incident #61066 with the Two way data binding sample. Please check it out.

Thanks
Ganesan

Loader.
Live Chat Icon For mobile
Up arrow icon