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.

How Do I access a GridListControl Embedded in a Cell

Thread ID:

Created:

Updated:

Platform:

Replies:

23937 Jan 25,2005 08:53 AM Jan 27,2005 09:38 AM Windows Forms 12
loading
Tags: GridControl
Adrian Lin
Asked On January 25, 2005 08:53 AM

I have a cell that has a grid list control in the essential grid. I want to be able to access that grid list control progammaticially and change/add values and look up values within that grid list control that is embedded within that cell. Thanks

Administrator [Syncfusion]
Replied On January 25, 2005 09:15 AM

To get at a GridListControl in a cell, you can use code such as: Private Sub GridDataBoundGrid1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As GridCurrentCellShowingDropDownEventArgs) Handles GridDataBoundGrid1.CurrentCellShowingDropDown Dim cc As GridCurrentCell = Me.GridDataBoundGrid1.CurrentCell If cc.Renderer.GetType() Is GetType(GridDropDownGridListControlCellRenderer) Then Dim cr As GridDropDownGridListControlCellRenderer = CType(cc.Renderer, GridDropDownGridListControlCellRenderer) cr.ListControlPart.DropDownRows = 12 cr.ListControlPart.AutoSizeColumns = True End If End Sub The GridListControl in the cell does not actually ''store'' any data. It just displays whatever data is in the style.DataSource that you specified for the cell. So, to "progammaticially and change/add values", you should try doing this in the DataSource you assigned to the style.

Adrian Lin
Replied On January 25, 2005 10:46 AM

>To get at a GridListControl in a cell, you can use code such as: > >Private Sub GridDataBoundGrid1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As GridCurrentCellShowingDropDownEventArgs) Handles GridDataBoundGrid1.CurrentCellShowingDropDown > Dim cc As GridCurrentCell = Me.GridDataBoundGrid1.CurrentCell > If cc.Renderer.GetType() Is GetType(GridDropDownGridListControlCellRenderer) Then > Dim cr As GridDropDownGridListControlCellRenderer = CType(cc.Renderer, GridDropDownGridListControlCellRenderer) > cr.ListControlPart.DropDownRows = 12 > cr.ListControlPart.AutoSizeColumns = True > End If >End Sub > > >The GridListControl in the cell does not actually ''store'' any data. It just displays whatever data is in the style.DataSource that you specified for the cell. So, to "progammaticially and change/add values", you should try doing this in the DataSource you assigned to the style. > > So does that mean since we pass our datasource to a table style we can only have one unique gridlist control in the essential datagrid? So if I wanted to have a gridlist control for states and one for presidents in two seprate cells this would not be possible?

Administrator [Syncfusion]
Replied On January 25, 2005 11:18 AM

You would have to set the style.DataSource for the two different cells to be different if you want different datasources to be used. You could do this using the grid.Model.QueryCellInfo event. In your handler, you would check e.RowIndex and e.ColIndex, and if these pointed to the particular cell, you would then set e.Style.DataSource to be the proper value depending upon which cell it is.

Adrian Lin
Replied On January 25, 2005 12:44 PM

Okay thank you clay I will try it. >You would have to set the style.DataSource for the two different cells to be different if you want different datasources to be used. > >You could do this using the grid.Model.QueryCellInfo event. In your handler, you would check e.RowIndex and e.ColIndex, and if these pointed to the particular cell, you would then set e.Style.DataSource to be the proper value depending upon which cell it is.

Adrian Lin
Replied On January 26, 2005 09:07 AM

I tried to do something similar to the examples and I can successfully pass a specific GridListControl to a specific cell depending on where the user clicked however the GridList doesn’t show on the first click of the dropdown it shows after the 2nd click. How can I get it show on the first click. I tried to do refresh and reactivate but it didn’t work. Here is my code: Private Sub GridControl1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs) _ Handles GridControl1.CurrentCellShowingDropDown Dim gcc_CurrentCell As Syncfusion.Windows.Forms.Grid.GridCurrentCell = Me.GridControl1.CurrentCell Dim i_CellCol As Integer = 0 Dim i_CellRow As Integer = 0 Dim gc_GridControl As New Syncfusion.Windows.Forms.Grid.GridControl Dim dt_DataTable As New DataTable("CC") Dim dr_DRow As DataRow Dim dc_DCol As DataColumn Dim i_NumbValueEntries As Integer = 0 Dim i_ValueCounter As Integer = 0 i_CellRow = gcc_CurrentCell.RowIndex i_CellCol = gcc_CurrentCell.ColIndex If i_CellCol = 2 Then gc_GridControl = al_StudbookId.Item((i_CellRow - 1)) i_NumbValueEntries = gc_GridControl.RowCount() dc_DCol = New DataColumn("Studbook ID") dt_DataTable.Columns.Add(dc_DCol) dc_DCol = New DataColumn("Date Entered") dt_DataTable.Columns.Add(dc_DCol) dc_DCol = New DataColumn("Method") dt_DataTable.Columns.Add(dc_DCol) For i_ValueCounter = 0 To i_NumbValueEntries dr_DRow = dt_DataTable.NewRow() dr_DRow(0) = gc_GridControl(i_ValueCounter, 0).Text dr_DRow(1) = gc_GridControl(i_ValueCounter, 1).Text dr_DRow(2) = gc_GridControl(i_ValueCounter, 2).Text dt_DataTable.Rows.Add(dr_DRow) Next GridControl1.TableStyle.DataSource = dt_DataTable End If End Sub >You would have to set the style.DataSource for the two different cells to be different if you want different datasources to be used. > >You could do this using the grid.Model.QueryCellInfo event. In your handler, you would check e.RowIndex and e.ColIndex, and if these pointed to the particular cell, you would then set e.Style.DataSource to be the proper value depending upon which cell it is.

Administrator [Syncfusion]
Replied On January 26, 2005 10:59 AM

Do not set the grid.TableStyle.DataSource. Instead set the DataSource directly on the dropdownlist that is about to be shown.
Private Sub gridControl1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As GridCurrentCellShowingDropDownEventArgs) Handles gridControl1.CurrentCellShowingDropDown
	Dim cc As GridCurrentCell = Me.gridControl1.CurrentCell
	If cc.Renderer.GetType() Is GetType(GridDropDownGridListControlCellRenderer) Then
		Dim cr As GridDropDownGridListControlCellRenderer = CType(cc.Renderer, GridDropDownGridListControlCellRenderer)

                ''define your data source some how....
                '' then set it
                cr.ListControlPart.DataSource = dt_DataTable 
         End If
End Sub

Adrian Lin
Replied On January 26, 2005 11:54 AM

I did exactlty as you stated and I still dont get the gridlist on the first click. I have to double click the drop down arrow a couple of times to get it to appear then it appears at one click. Here is my code with your adjustments: Private Sub GridControl1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs) _ Handles GridControl1.CurrentCellShowingDropDown Dim gcc_CurrentCell As Syncfusion.Windows.Forms.Grid.GridCurrentCell = Me.GridControl1.CurrentCell Dim i_CellCol As Integer = 0 Dim i_CellRow As Integer = 0 Dim gc_GridControl As New Syncfusion.Windows.Forms.Grid.GridControl Dim dt_DataTable As New DataTable("CC") Dim dr_DRow As DataRow Dim dc_DCol As DataColumn Dim i_NumbValueEntries As Integer = 0 Dim i_ValueCounter As Integer = 0 Dim mea_MouseEvent As System.Windows.Forms.MouseEventArgs If gcc_CurrentCell.Renderer.GetType() Is GetType(Syncfusion.Windows.Forms.Grid.GridDropDownGridListControlCellRenderer) Then i_CellRow = gcc_CurrentCell.RowIndex i_CellCol = gcc_CurrentCell.ColIndex Dim cr_CurrentDList As Syncfusion.Windows.Forms.Grid.GridDropDownGridListControlCellRenderer = _ CType(gcc_CurrentCell.Renderer, Syncfusion.Windows.Forms.Grid.GridDropDownGridListControlCellRenderer) If i_CellCol = 2 Then gc_GridControl = al_StudbookId.Item((i_CellRow - 1)) i_NumbValueEntries = gc_GridControl.RowCount() dc_DCol = New DataColumn("Studbook ID") dt_DataTable.Columns.Add(dc_DCol) dc_DCol = New DataColumn("Date Entered") dt_DataTable.Columns.Add(dc_DCol) dc_DCol = New DataColumn("Method") dt_DataTable.Columns.Add(dc_DCol) For i_ValueCounter = 0 To i_NumbValueEntries dr_DRow = dt_DataTable.NewRow() dr_DRow(0) = gc_GridControl(i_ValueCounter, 0).Text dr_DRow(1) = gc_GridControl(i_ValueCounter, 1).Text dr_DRow(2) = gc_GridControl(i_ValueCounter, 2).Text dt_DataTable.Rows.Add(dr_DRow) Next cr_CurrentDList.ListControlPart.DataSource = dt_DataTable End If End If End Sub >Do not set the grid.TableStyle.DataSource. Instead set the DataSource directly on the dropdownlist that is about to be shown. > > >
>Private Sub gridControl1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As GridCurrentCellShowingDropDownEventArgs) Handles gridControl1.CurrentCellShowingDropDown
>	Dim cc As GridCurrentCell = Me.gridControl1.CurrentCell
>	If cc.Renderer.GetType() Is GetType(GridDropDownGridListControlCellRenderer) Then
>		Dim cr As GridDropDownGridListControlCellRenderer = CType(cc.Renderer, GridDropDownGridListControlCellRenderer)
>
>                ''define your data source some how....
>                '' then set it
>                cr.ListControlPart.DataSource = dt_DataTable 
>         End If
>End Sub
>

Administrator [Syncfusion]
Replied On January 26, 2005 01:43 PM

Here is a sample that seems to display on the initial drop OK for me using 2.1.0.9. http://www.syncfusion.com/forums/Uploads/GC_GLC_VB.zip Are you initially setting the style.DisplayMember, style.ValueMember, style.DataSource and style.CellType for the initial cell in addition to setting the DataSource on the droplist?

Adrian Lin
Replied On January 27, 2005 08:55 AM

Ok, I tested your sample and it worked as expected. I then decided to just do this to set an intial drop down to a cell and I saw I could do this for every cell and have a distinct gridlist control for every cell using the code your provided on the form load event: Dim dt As New DataTable("MyTable") Dim nCols As Integer = 4 Dim nRows As Integer = 10 Dim i As Integer Dim j As Integer For i = 0 To nCols - 1 dt.Columns.Add(New DataColumn(String.Format("Col{0}", i))) Next For i = 0 To nRows - 1 D''im dr As DataRow = dt.NewRow() For j = 0 To nCols - 1 dr(j) = String.Format("row{0}-{1}", i, j) Next dt.Rows.Add(dr) Next Me.GridControl1(2, 2).DataSource = dt Me.GridControl1(2, 2).ValueMember = "Col1" Me.GridControl1(2, 2).DisplayMember = "Col1" '' Me.GridControl1(2, 2).CellType = "GridListControl" I then wanted to have it so that I mark the cell as a gridlist control and I define its display member and cell type and value memeber but I didnt want to pass a datasource to the cell until the drop down event was called and then I got the same issue as before i keep having to double click the arrow then click again to get theh drop down. This is what I did: Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Me.GridControl1(2, 2).Text = "BOING" Me.GridControl1(2, 2).ValueMember = "Col1" Me.GridControl1(2, 2).DisplayMember = "Col1" Me.GridControl1(2, 2).CellType = "GridListControl" End Sub Then I just copied your dropdown code: Private Sub GridControl1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs) Handles GridControl1.CurrentCellShowingDropDown Dim cc As GridCurrentCell = Me.GridControl1.CurrentCell Dim cr As GridDropDownGridListControlCellRenderer = cc.Renderer Dim dt As New DataTable("MyTable") Dim nCols As Integer = 4 Dim nRows As Integer = 10 Dim r As New Random Dim k As Integer = r.Next(10) Dim i As Integer Dim j As Integer For i = 0 To nCols - 1 dt.Columns.Add(New DataColumn(String.Format("Col{0}", i))) Next For i = 0 To nRows - 1 Dim dr As DataRow = dt.NewRow() For j = 0 To nCols - 1 dr(j) = String.Format("row{0}-{1}", i, k) ''r makes it different with each drop Next dt.Rows.Add(dr) Next cr.ListControlPart.DataSource = dt End Sub I still get the same issue. So my question is do I have to preset a data source to a cell for it to drop down apporietly and in that drop down I can change cells within the gridlist control or can I assign a datasource on the fly to a cell that is of type gridlist control on the dropdown event? >Here is a sample that seems to display on the initial drop OK for me using 2.1.0.9. > >http://www.syncfusion.com/forums/Uploads/GC_GLC_VB.zip > >Are you initially setting the style.DisplayMember, style.ValueMember, style.DataSource and style.CellType for the initial cell in addition to setting the DataSource on the droplist?

Administrator [Syncfusion]
Replied On January 27, 2005 09:09 AM

In your sample, initially set up a dummy datasource with a single item in it and assign it to grid.TableStyle.DataSource. Maybe this will make things work the first time.

Adrian Lin
Replied On January 27, 2005 09:20 AM

Nope, doesnt work well. I get a gridlist control with the 4 cols but no rows outside of the header. Then if I double click and click i get the gridlist control specifed in the event. I guess I have to do preassignments. I just thought it would a lot more efficient to call a gridlist control e.g. assign a datasource when needed not preassign. This is an issue for me because we have several variables that are going to have a history and we want the user to see the history via a gridlist control when they click on the cell containing that variable. Thanks, >In your sample, initially set up a dummy datasource with a single item in it and assign it to grid.TableStyle.DataSource. Maybe this will make things work the first time. > >

Administrator [Syncfusion]
Replied On January 27, 2005 09:38 AM

If you send a sample project showing the problem to support@syncfusion.com and mention this thread in the subject line, we can try to spot the problem here.

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.

;