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.

Binding several columns

Thread ID:

Created:

Updated:

Platform:

Replies:

30810 Jun 24,2005 04:27 AM Jul 14,2005 09:06 AM Windows Forms 11
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On June 24, 2005 04:27 AM

Hello: I''m binding a column in a GDBG with a datasource using a combocox column. This is the code: GridBoundColumn gbcIncidencia=this.incidenciasGridDataBoundGrid.Binder.InternalColumns[0]; gbcIncidencia.HeaderText="Nombre"; gbcIncidencia.MappingName="IdIncidencia"; gbcIncidencia.StyleInfo.CellType="ComboBox"; gbcIncidencia.StyleInfo.DataSource=incidencias; gbcIncidencia.StyleInfo.DisplayMember="NombreIncidencia"; gbcIncidencia.StyleInfo.ValueMember="IdIncidencia"; gbcIncidencia.StyleInfo.ShowButtons=GridShowButtons.Show; gbcIncidencia.StyleInfo.ExclusiveChoiceList=true; I would like to get not only a valuemember for my mapping column from the datasource, but to get values for several columns at the same time. How can I bind several columns to the same datasource? Best regards

Administrator [Syncfusion]
Replied On June 24, 2005 04:40 AM

If you do not set ValueMember, then the grid will assume that you are using the actual DataRowView object as the cell value. This means you can get at any of the columns in the DataRowView. Take a look at the \Syncfusion\Essential Studio\3.2.1.0\Windows\Grid.Windows\Samples\CellTypes\ComboboxCells sample. It has examples of using ValueMember as unset.

Administrator [Syncfusion]
Replied On July 13, 2005 12:29 PM

I''m using GDBC 3.2.1. I checked the example that you quoted. I don''t see any sample out there with valuemeber unset. SO, I tried it my self. Now, When i select an item from the combo box, the selected item is not displayed in the combox and currentcellchanged event is also not trigered. Can you tell how to do this. Thanks Shankar >If you do not set ValueMember, then the grid will assume that you are using the actual DataRowView object as the cell value. This means you can get at any of the columns in the DataRowView. Take a look at the \Syncfusion\Essential Studio\3.2.1.0\Windows\Grid.Windows\Samples\CellTypes\ComboboxCells sample. It has examples of using ValueMember as unset. >

Shankar Ramasubramanian
Replied On July 13, 2005 12:48 PM

Hi, I''m using GDBC 3.2.1. I checked the example that you quoted. I don''t see any sample out there with valuemeber unset. SO, I tried it my self. Now, When i select an item from the combo box, the selected item is not displayed in the combox and currentcellchanged event is also not trigered. Can you tell how to do this. Thanks Shankar

Administrator [Syncfusion]
Replied On July 13, 2005 12:56 PM

Look at grid row 83 in that sample. It should read "ComboBox using Datasource, ValueMember = Empty" and this is a section that has an empty ValueMember. Look in mainform.cs around line 145. In your case, have you set the DisplayMember on the style? This should pick out what property should be displayed in the cell. Here is a minimal sample. http://www.syncfusion.com/Support/user/uploads/GC_CustomObject_7f319ea1.zip

Shankar Ramasubramanian
Replied On July 13, 2005 01:53 PM

All your examples use grid control. But I''m using Grid Databound grid. Can your try with GDBG.

Administrator [Syncfusion]
Replied On July 13, 2005 03:07 PM

The same code should work in a GridDataBoundGrid. You just have to make sure the column in your datasource is the type of your object. http://www.syncfusion.com/Support/user/uploads/GC_CustomObject_bccfc3d3.zip

Shankar Ramasubramanian
Replied On July 13, 2005 04:06 PM

If you look at my sample, the display member disappears.You have to move outof the row.(set enableAddnew = true Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click AddHandler GridDataBoundGrid1.CurrentCellChanged, AddressOf GDBG_CurrentCellChanged Dim dt As New DataTable dt.Columns.Add(New DataColumn("OrderID")) dt.Columns.Add(New DataColumn("Order Date")) dt.Columns.Add(New DataColumn("Customer")) dt.Columns.Add(New DataColumn("Currency")) dt.Columns.Add(New DataColumn("Amount")) Dim dt2 As New DataTable dt2.Columns.Add(New DataColumn("CurrencyID")) dt2.Columns.Add(New DataColumn("CurrencyCode")) Dim row1 As DataRow row1 = dt2.NewRow row1("CurrencyID") = "1" row1("CurrencyCode") = "USD" dt2.Rows.Add(row1) row1 = dt2.NewRow row1("CurrencyID") = "2" row1("CurrencyCode") = "AUD" dt2.Rows.Add(row1) Dim dt1 As New DataTable dt1.Columns.Add(New DataColumn("CustomerID")) dt1.Columns.Add(New DataColumn("CustomerName")) dt1.Columns.Add(New DataColumn("ZipCode")) Dim row As DataRow row = dt1.NewRow row("CustomerId") = "1" row("CustomerName") = "Customer1" row("ZipCode") = "10001" dt1.Rows.Add(row) row = dt1.NewRow row("CustomerId") = "2" row("CustomerName") = "Customer2" row("ZipCode") = "10002" dt1.Rows.Add(row) GridDataBoundGrid1.DataSource = dt GridDataBoundGrid1.Refresh() Dim style As GridStyleInfo = Me.GridDataBoundGrid1.Binder.InternalColumns("Customer").StyleInfo ''GridDataBoundGrid1.Model.ColStyles(3) style.CellType = "ComboBox" style.CellValueType = GetType(DataRowView) style.DataSource = dt1 style.DisplayMember = "CustomerName" style.DropDownStyle = GridDropDownStyle.Exclusive Dim style1 As GridStyleInfo = Me.GridDataBoundGrid1.Binder.InternalColumns("Currency").StyleInfo ''GridDataBoundGrid1.Model.ColStyles(3) style1.CellType = "ComboBox" style1.CellValueType = GetType(System.String) style1.DataSource = dt2 style1.DisplayMember = "CurrencyCode" style1.ValueMember = "CurrencyID" style1.DropDownStyle = GridDropDownStyle.Exclusive End Sub Private Sub GDBG_CurrentCellChanged(ByVal sender As Object, ByVal e As EventArgs) If GridDataBoundGrid1.CurrentCell.ColIndex = 3 Then MsgBox(CType(CType(GridDataBoundGrid1.CurrentCell.Renderer.ControlValue, DataRowView).Item("ZipCode"), String)) End If End Sub

Administrator [Syncfusion]
Replied On July 13, 2005 05:21 PM

Here is what is wrong. You have have this set: dt.Columns.Add(New DataColumn("Customer")) which means the customer column in your datatable is a string. But in the grid, you are saying this column is DataRowView. Whatever you have in the DataTable for this column (you say a string) is what must be the value stored in grid. So, you cannot use the DataRowView in this case. Instead, if your combobox datatable has a primary key, then you can use that as teh ValueMember. Then you can use this primary key to look up teh datarowview when you need to know if base on knowing the value of teh grid cell.

Administrator [Syncfusion]
Replied On July 13, 2005 05:39 PM

Clay, From you post on this thread on 6/24/2005, I understood that if i don''t set the ValueMember, cell value will be datarowview. That''s what i was trying the whole day. But Only way to access the other columns in ComboBox Table is to store primary key as valuemember and filter the table to get other columns. Is my case, to get the zipCode 1.Set VAlue member as customer ID 2. On CurrentCellChanged get the Value 3. Query the Combobox datatable on the primary key to get other columns Is that right?

Administrator [Syncfusion]
Replied On July 13, 2005 06:21 PM

If you do not set the valuemember, the combbobox does return the datarowview as the value. But the grid has to be able to store this value somewhere. In a GridControl, you can handle this. But in a GridDataBoundGrid, the grid column must match the column type in the grid''s datasource. This means your grid''s datatable would have to store the datarowviews from the combobox datatable which is possible, but is not how datatables are normally designed. Normally, only a primary key is stored in teh grid''s datatable. Yes, what you described is what you would have to do if you do not want to store you combobox datarowviews as values in the grid''s datatable. Here is a little sample. http://www.syncfusion.com/Support/user/uploads/GDBG_ComboBox_df81de.zip

Administrator [Syncfusion]
Replied On July 14, 2005 09:06 AM

Clay, Thanks for the prompt responses and excellent support. Thanks again shankar

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.

;