Hello,
*** Any body there who can help me out from following issue ***
I have a user control with a normal combobox and a button in it. combo box has values like A,B,C,.....X,Y,Z
I have a form with a GridDataBoundGrid with 5 columns; Code, FirstName, MiddleName, LastName, and Remarks.
I want to put this user control on a separate column (should be added separately in grid) which should be linked with column MiddleName.
I am populating grid with an xml file with the same fields as mention above with many records.
When the grid gets populated, all the comboboxes should be initialized with the corresponding value in column MiddleName (for all the rows in grid).
User should be able to select any item inside the combobox in the desired row of grid. The value under the column MiddleName on selected row should be changed according to the value of in combobox.
When user click button (available inside user control), it simply opens another form (on which there are details about that MiddleName like; K for Kumar or Kaushik, and P for Parasad, Prakash, or Pratap, and so on, this is just to provide some description about the MiddleName that he has selected).
I need your help in the issue, that how can i bind the User control with Grid and how can I manipulate combobox as well.
Please help me out in this.
Awaiting reply.
Thanks
Sharad Kapil Sharma
kaps444@yahoo.com
sharad_kapil2004@yehoo.com
AD
Administrator
Syncfusion Team
July 7, 2005 01:32 PM UTC
Here is a sample that shows how you can have a dropdown usercontrol as a CellType.
\Syncfusion\Essential Studio\3.2.1.0\Windows\Grid.Windows\Samples\In Depth\DropDownFormAndUserControlSample
Here is another sample that shows how you can display a UserControl as a CellType.
\Syncfusion\Essential Studio\3.2.1.0\Windows\Grid.Windows\Samples\DataBound\RepeaterUserControlSample
But it may be simpler to add 2 unbound columns, one being our standard "ComboBox" CellType and the other being our "PushButton" CellType. This way you would not need any custom cell controls avoiding additional work on your part. To use this technique just set add GridBoundColumns to the grid.GridBoundColumns collection, one for each of the real columns in your DataSource. Then add two more GridBoundColumns using MappingNames that are not in your datasource. Thee last two columns would be your unbound columns. Then you would handle the grid.Model.QueryCellInfo. There, if e.ColIndex points to your unbound combobox column, you would set e.Style.CellValue to be the value from teh bound column you mentioned above.
SS
Sharad Sharma
July 8, 2005 05:44 AM UTC
Hello,
Thanks for reply.
Presently I have version 2.1.0.9 installed on my system.
In both the samples DropDownFormAndUserControlSample and RepeaterUserControlSample, GridControl is used for required functionality.
But I have already coded-in much using GridDataBoundGrid control. So this will be a big problem for me to re-code everything with gridControl. Another issue is that Client wants all the functionalities on GridDataBoundGrid.
Can you suggest me any middle way to achieve the task.
Thanks and regards,
Sharad
AD
Administrator
Syncfusion Team
July 8, 2005 08:00 AM UTC
There is no reason you cannot use the cell control shown in those samples in a GridDataboundGrid. You set the CellType on the GridBoundColumn.StyleInfo for the column and you add the cell model using gridDataBoundGrid1.Model.CellModels.Add instead of adding it using gridControl1.CellModels.Add. But in the end, it is the same thing.
You will face the problem of how you move the information stored in your DataSource for that column into your UserControl, but you would have to do this no matter what grid you are using.
SS
Sharad Sharma
July 12, 2005 09:13 AM UTC
Hi Clay Burch,
I have tried a lot with the sample, suggested by you. But could not fing the solution.
Can you please write a small code for me with following functionality.
A Usercontrol with 1 combo box and one button.
A GridDataBoundGrid with the above usercontrol on the form.
Thanks and regards,
KAPIL''S
MC
Martin Cyr
July 12, 2005 12:34 PM UTC
As Clay previously stated, you can do what you need in a GDBG as you would in a GridControl. Just do the same thing as you would''ve done with the GridControl on the GDBG. That is create yourself two new classes inheriting from GridGenericControlCellModel and GridGenericControlCellRenderer. In the model, override the CreaterRenderer to return a new instance of the renderer you created. In the renderer simply create an instance of the usercontrol you want to display (or maybe two, one static and one active, see the repeater grid control for details) and override the OnDraw sub and change the event.style.control to point to your user control and it''s also in the OnDraw that you will affect the data to your user control (the OnDraw has the row and col IDs it is currently drawing).
It should looks something like this :
Public Class MyUserControlCellModel
Inherits GridGenericControlCellModel
Public Sub New(ByVal parentGridModel As GridModel)
MyBase.New(parentGridModel)
End Sub
Public Overrides Function CreateRenderer(ByVal grid As GridControlBase) As GridCellRendererBase
Return New MyUserControlCellRenderer(grid, Me)
End Function ''CreateRenderer
End Class
Public Class MyUserControlCellRenderer
Inherits GridGenericControlCellRenderer
Private activeControl As MyUserControl
Private staticControl As MyUserControl
Public Sub New(ByVal grid As GridControlBase, ByVal model As GridCellModelBase)
MyBase.New(grid, model)
activeControl = New MyUserControl
staticControl = New MyUserControl
MakeUnBuffered(staticControl) ''This is not necesarily needed
End Sub
Protected Overrides Sub OnDraw(ByVal g As Graphics, ByVal clientRectangle As Rectangle, ByVal rowIndex As Integer, ByVal colIndex As Integer, ByVal style As GridStyleInfo)
''Get some space to work around
clientRectangle.Inflate(-1, -1)
If Me.ShouldDrawFocused(rowIndex, colIndex) Then
''Set the values to be diplayed in the active user control HERE
style.Control = activeControl
Else
''Set the values to be diplayed in the static user control HERE
style.Control = staticControl
End If
''Now we call the base drawing sub to do the rest of the job
MyBase.OnDraw(g, clientRectangle, rowIndex, colIndex, style)
End Sub ''OnDraw
''Ensure that the controls are not double buffered (faster I think)
Private Sub MakeUnBuffered(ByVal c As Control)
Dim mInfo As System.Reflection.MethodInfo = GetType(Control).GetMethod("SetStyle", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.InvokeMethod Or System.Reflection.BindingFlags.NonPublic)
If Not (mInfo Is Nothing) Then
mInfo.Invoke(c, New Object() {ControlStyles.DoubleBuffer, False})
End If
If c.Controls.Count > 0 Then
Dim c1 As Control
For Each c1 In c.Controls
c1.CausesValidation = False
MakeUnBuffered(c1) ''recursive call
Next c1
End If
End Sub ''MakeUnBuffered
End Class
MC
Martin Cyr
July 12, 2005 12:45 PM UTC
I forgot to mention that you should also register the newly created Model with the grid in wich it needs to be used, by using the CellModels.Add() method and then setting the desired style or range CellType property to the newly registered model.
YourGridDataBoundGrid.Model.CellModels.Add("MyUserControlCell", new MyUserControlCellModel(YourGridDataBoundGrid.Model))
YourGridDataBoundGrid.BaseStylesMap("Standard").StyleInfo.CellType = "MyUserControlCell"
SS
Sharad Sharma
July 14, 2005 11:53 AM UTC
I have converted you VB-code in c#.
*****
using System;
using Syncfusion.Windows.Forms.Grid;
using System.Drawing;
using System.Windows.Forms;
namespace MyNamespace
{
public class MyUserControlCellModel : GridGenericControlCellModel
{
public MyUserControlCellModel()
{
}
public void New(GridModel parentGridModel)
{
this.New(parentGridModel);
}
public override GridCellRendererBase CreateRenderer(GridControlBase grid)
{
return (new MyUserControlCellRendrer(grid,this)); // return following class object (cons.)
}
}
public class MyUserControlCellRendrer : GridGenericControlCellRenderer
{
private MyUserControlCellModel activeControl;
private MyUserControlCellModel staticControl;
public void New(GridControlBase grid, GridCellModelBase model)
{
this.New(grid, model);
activeControl = new MyUserControl(); // from where "MyUserControl" name is coming ?
staticControl = new MyUserControl();
MakeUnBuffered(staticControl); // this is not necessarily needed
}
protected override void OnDraw(Graphics g, Rectangle clientRectangle, Int32 rowIndex, Int32 colIndex, GridStyleInfo style)
{
clientRectangle.Inflate(-1,-1);
if (this.ShouldDrawFocused(rowIndex, colIndex))
{
style.Control = activeControl;
}
else
{
style.Control = staticControl;
}
this.OnDraw(g, clientRectangle, rowIndex, colIndex);
}
private void MakeUnBuffered(Control c)
{
System.Reflection.MethodInfo mInfo = GetType(Control).GetMethod("SetStyle", System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.InvokeMethod |
System.Reflection.BindingFlags.NonPublic);
if (!(mInfo == null))
{
mInfo.Invoke(c, new object[]{ControlStyles.DoubleBuffer, false});
}
if (c.Controls.Count>0)
{
foreach (Control c1 in c.Controls)
{
c1.CausesValidation = false;
MakeUnBuffered(c1); // recursive call
}
}
}
}
}
*****
Please examine whether the code if OK, because I am confused about "MyUserControl" which you have used inside the code.
I used "MyUserControl" for the UserControl Name
Awaiting reply.
Thanks
Sharad
SS
Sharad Sharma
July 14, 2005 01:17 PM UTC
Hello,
Can you please send the C# version of above VB.NET code. As I am not comfortable with VB.NET
Thanks & Regards
AD
Administrator
Syncfusion Team
July 14, 2005 01:42 PM UTC
There is a C# sample in these two threads that put a user control in a column in a griddataboundgrid.
http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=31655
http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=29343
MC
Martin Cyr
July 14, 2005 08:04 PM UTC
SS
Sharad Sharma
July 15, 2005 08:27 AM UTC
Hi Martin,
Thanks.
I viewed UCCellDemo_1007.zip
UCCellDemo is using following references ...
1.Syncfusion.Core
2.Syncfusion.Grid.Base
3.Syncfusion.Grid.Windows
4.Syncfusion.Shared.Base
5.Syncfusion.Shared.Windows
Are there Control available in SyncFucionn 2.1.0.9 ???
We are presently working in 2.1.0.9. version;
Can you helo me out in this i9ssue.
Thanks.
AD
Administrator
Syncfusion Team
July 15, 2005 09:51 AM UTC
Those are the references for the 3.x version of our libraries. You should remove those references and add the ones for your 2.x which are syncfusion.shared and syncfusion.grid. You should also delete the license.licx file from the project and the folder, and then open up the form and resize the grid so the proper 2.x license.licx file will be added to the project.
SS
Sharad Sharma
July 15, 2005 11:30 AM UTC
Thanks Clay,
SS
Sharad Sharma
July 15, 2005 11:48 AM UTC
Thank Clay,
It works.
SI
singa
July 16, 2005 05:36 AM UTC
hi Clay Burch:
how can I get them?
1.Syncfusion.Core
2.Syncfusion.Grid.Base
3.Syncfusion.Grid.Windows
4.Syncfusion.Shared.Base
5.Syncfusion.Shared.Windows
>Those are the references for the 3.x version of our libraries. You should remove those references and add the ones for your 2.x which are syncfusion.shared and syncfusion.grid. You should also delete the license.licx file from the project and the folder, and then open up the form and resize the grid so the proper 2.x license.licx file will be added to the project.
AD
Administrator
Syncfusion Team
July 16, 2005 07:40 AM UTC
You need to have version 3.2.1.0 of Essential Grid installed. If you have a valid subscription, you can download this version from your Direct Trac home page. https://www.syncfusion.com/Support/DirectTrac/logon.aspx?URL=/Support/DirectTrac/default.aspx
If you do not own Essential Grid, you can order it online at:
https://www.syncfusion.com/sales/orderonline.aspx
You can download a trial version of our Essential Studio (which includes Essential Grid) from this link:
http://www.syncfusion.com/Downloads/evaluation.aspx