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
close icon

Data-binding

I've been playing around with the data-binding support for the Syncfusion grid without much success. Unfortunately I haven't found documentation/samples at that respect, so I've been "guessing" about assigning properties like DataSource, DisplayMember and ValueMember (like a regular Combo-box in .NET) for GridStyleInfo instances, but I haven't been able to display data just by doing that. My specific question is if Syncfusion grid supports Data-binding in the regular way .NET's controls use it without using the Virtual mode of the grid (supporting those QueryXXX events)? The idea is that the grid refreshes its DataSource automatically and viceversa on any change. Thanks in advance for you response, Diego Diaz

9 Replies

SH Stefan Hoenig Syncfusion Team July 12, 2002 12:49 PM UTC

> I've been playing around with the data-binding support for the Syncfusion grid without much success. Unfortunately I haven't found documentation/samples at that respect, so I've been "guessing" about assigning properties like DataSource, DisplayMember and ValueMember (like a regular Combo-box in .NET) for GridStyleInfo instances, but I haven't been able to display data just by doing that. > > My specific question is if Syncfusion grid supports Data-binding in the regular way .NET's controls use it without using the Virtual mode of the grid (supporting those QueryXXX events)? The idea is that the grid refreshes its DataSource automatically and viceversa on any change. > > Thanks in advance for you response, > > Diego Diaz There is a GridDataBoundGrid that you can drop onto a form and then set Datasource and DataMember properties very similar to the Windows Forms DataGrid. The GridBoundColumns collection of the GridDataBoundGrid lets you specify which columns to show. The users guide has a small tutorial how to use GridDataBoundGrid in a form. Stefan


DD Diego Diaz July 12, 2002 02:00 PM UTC

Thanks Stefan for your quick response. SyncFusion has an excellent Technical Support. I've tried it out, and it's just great. However, I am still curious about the right way to use those properties (DataSource, DisplayMember and ValueMember) at the GridStyleInfo class level. Can you give me a brief overview about how to use them? Should I call something special for applying them after assigning them? (My question applies to the general GridControl rather than to the GridBound one) Thanks, Diego Diaz


SH Stefan Hoenig Syncfusion Team July 12, 2002 03:52 PM UTC

The intention behind these properties is to allow cell types to provide data binding support for indivdual cells. The DataSource property specifies a data source that holds items to be displayed in a dropdown list. A datasource can be specified instead of manually filling the choicelist with string entries. The property affects the behavior or appearance of the following cell types: ComboBox (GridComboBoxCellRenderer) DropDownGridListControl (GridDropDownGridListControlCellRenderer) Here is some sample code snippet: ArrayList USStates = new ArrayList() ; USStates.Add(new USState("Alabama", "AL", 0)); USStates.Add(new USState("Washington", "WA", 1)) ; USStates.Add(new USState("West Virginia", "WV", 2)); USStates.Add(new USState("Wisconsin", "WI", 3)) ; USStates.Add(new USState("Wyoming", "WY", 4)); standard.DataSource = USStates ; standard.DisplayMember = "LongName" ; standard.ValueMember = "ShortName" ; model[rowIndex, 3].CellType = "GridListControl"; model[rowIndex, 3].ChoiceList = items; model[rowIndex, 3].DataSource = USStates ; model[rowIndex, 3].ExclusiveChoiceList = true; I also attached more as zip file. Our goal is also to have these properties work with binding a column in a databound grid to a table with forein keys, but that is not working perfect right now and I am actually gonna work on that soon. Stefan


DD Diego Diaz July 12, 2002 04:21 PM UTC

I was missunderstanding the purpose of these properties, but now it makes sense to me. Thanks for your explanation and example. Regarding the GridDataBoundGrid control, is there a way to get the MSAccess look-and-feel ? in which you could define the Style of a given GridBoundColumn (let's say to a ComboBox) but when displaying the grid, only the combo-box is drawn for the current cell, but not for all the cells in the column (like DataGrid does)? Thanks, Diego Diaz


SH Stefan Hoenig Syncfusion Team July 12, 2002 05:52 PM UTC

> I was missunderstanding the purpose of these properties, but now it makes sense to me. Thanks for your explanation and example. > > Regarding the GridDataBoundGrid control, is there a way to get the MSAccess look-and-feel ? in which you could define the Style of a given GridBoundColumn (let's say to a ComboBox) but when displaying the grid, only the combo-box is drawn for the current cell, but not for all the cells in the column (like DataGrid does)? > > Thanks, > > Diego Diaz style.ShowButtons = GridShowButtons.ShowCurrentCell should do it. Stefan


DD Diego Diaz July 15, 2002 09:53 AM UTC

Thanks Stefan, Syncfusion's controls are amazing. Congratulations for those outstanding products! Although, I have some additional questions. I haven't figured out how to do the following minor tasks with the GridDataBoundGrid control. I would appreciate any help at this respect. * How can I get a MouseUp/Click event on Columns' Headers? I need to implement a context-menu after a column's header is right-clicked. I need to be able to recognize which column was clicked. * How can I disable the "move cells" behavior when dragging a cell from its border? In some cases, I need to use a grid just for displaying results, therefore, it has to be read-only. * How can I hide/dissapear the Row-selectors column? * Does this control have the capability of automatically adjust its rows/headers' height and width according to its content? I have some use-cases in which I need to present multi-lined headers (strings with characters). Thanks in advance for your assistance, Diego Diaz


CB Clay Burch Syncfusion Team July 15, 2002 01:25 PM UTC

1) Here is code that catches a mousedown event and tests to see if it is a right-click on a header. There is a FAQ (http://www.syncfusion.com/KB/Grid/Grid_c26c.asp#q547q) that uses a similar technique to display a context menu for any cell.
private void gridDataBoundGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
	if(e.Button == MouseButtons.Right)
	{
		Point clickPoint = gridDataBoundGrid1.PointToClient(Cursor.Position);
		int rowIndex, colIndex;
		gridDataBoundGrid1.PointToRowCol(clickPoint, out rowIndex, out colIndex);
		if(rowIndex == 0 && colIndex > 0)
			MessageBox.Show("gridDataBoundGrid1_MouseDown");
	}
}
2) Look at the ControllerOptions property. You need to uncheck the OleDataSource and/or OleDataTarget flags. 3) The row headers are column 0. You can hide column 0 from code with
	this.gridDataBoundGrid1.Model.HideCols[0] = true;

4) To autosize columnwidths or rowheights, you can use code such as
//autosize the colwidths of the col header (row 0)
this.gridDataBoundGrid1.Model.ColWidths.ResizeToFit(GridRangeInfo.Row(0));

You'll notice in the above code, we accessed properties in the Model member of GridDataBoundGridControl. If you are using the GridControl instead, you access these properties directly from GridControl, and do not have to use GridControl.Model.


DD Diego Diaz July 15, 2002 04:04 PM UTC

Does the GridDataBoundGrid component have a property that allows setting the text to display if a given value is DBNull? (Like NullText in DataGrid?) Or does this scenario need to be managed by using formatting events? Thanks, Diego Diaz


CB Clay Burch Syncfusion Team July 16, 2002 05:57 AM UTC

Currently, you have to handle this through events. Here is one way to do this.
private void gridDataBoundGrid2_DrawCell(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellEventArgs e)
{
	if(e.ColIndex > 0 && e.RowIndex > 0 && e.Style.CellValue == "")
	{
		e.Style.Text = "MyNullValue";
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon