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.
Unfortunately, activation email could not send to your email. Please try again.

Data-binding

Thread ID:

Created:

Updated:

Platform:

Replies:

587 Jul 12,2002 08:31 AM Jul 16,2002 01:57 AM Windows Forms 9
loading
Tags: GridControl
Diego Diaz
Asked On July 12, 2002 08:31 AM

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

Stefan Hoenig [Syncfusion]
Replied On July 12, 2002 08:49 AM

> 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

Diego Diaz
Replied On July 12, 2002 10:00 AM

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

Stefan Hoenig [Syncfusion]
Replied On July 12, 2002 11:52 AM

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

Diego Diaz
Replied On July 12, 2002 12:21 PM

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

Stefan Hoenig [Syncfusion]
Replied On July 12, 2002 01:52 PM

> 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

Diego Diaz
Replied On July 15, 2002 05:53 AM

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 \n characters). Thanks in advance for your assistance, Diego Diaz

Clay Burch [Syncfusion]
Replied On July 15, 2002 09:25 AM

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.

Diego Diaz
Replied On July 15, 2002 12:04 PM

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

Clay Burch [Syncfusion]
Replied On July 16, 2002 01:57 AM

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";
	}
}

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;