 |
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

January 2nd, 2006, 09:19 AM
|
Registered User
|
|
Join Date: Jan 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
UserControls can be added in datagridTextBoxColumn
Hi all
I have a confusion that weather user controls
can be added as a column of datagrid through datagrid TextBox Column
AS i made a user control but that is not added with its full functionalities in the datagrid.
means many properties are not working when i embed a user control inside datagrid Column.
Thanks in advance
Thanks & Regards
Hema Chaudhry
|

January 2nd, 2006, 11:54 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
You can put any control into a datagrid template column. And technically you could programmatically insert any control into a non-template datagrid column by accessing the datagrid's items collection.
How are you trying to access your user control such that you beleive it is not working properly? Can you post a code sample of what you are trying to do?
- Peter
|

January 3rd, 2006, 01:51 AM
|
Registered User
|
|
Join Date: Jan 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
'This is My User Control Declaration
Private WithEvents MultiColumnComboBox1 As New MultiColumnComboBox.MultiColumnComboBox
'This Function Populate Datgrid with data
Private Sub PopulateGrid()
Me.DataGrid1.DataSource = dtbl
If Not DataGrid1.TableStyles.Contains("tbBill") Then
dgTblStyle = New DataGridTableStyle
dgTblStyle.MappingName = dtbl.TableName
Me.DataGrid1.TableStyles.Add(dgTblStyle)
Me.dgTblStyle.RowHeadersVisible = False
Me.dgTblStyle.AllowSorting = False
Me.dgTblStyle.PreferredRowHeight = 22
colStyle = Me.DataGrid1.TableStyles(0).GridColumnStyles
colStyle(0).Width = 100
colStyle(1).Width = 150
colStyle(2).Width = 100
colStyle(3).Width = 180
colStyle(0).Alignment = HorizontalAlignment.Center
colStyle(1).Alignment = HorizontalAlignment.Center
colStyle(2).Alignment = HorizontalAlignment.Center
colStyle(3).Alignment = HorizontalAlignment.Center
End If
datagridtextBox = CType(Me.DataGrid1.TableStyles(0).GridColumnStyles (1), DataGridTextBoxColumn)
'propeties to be set for MultiCOlumns ComboBox
MultiColumnComboBox1.ColumnSize = "50,50"
MultiColumnComboBox1.ColumnTitle = "EmpCode,EmpName"
MultiColumnComboBox1.DataFieldList = "EmpCode"
MultiColumnComboBox1.DataFieldToDisplay = "EmpName" MultiColumnComboBox1.DataSource = Nothing
MultiColumnComboBox1.Name = "MultiColumnComboBox1"
MultiColumnComboBox1.AddItem("EmpCode0,EmpName0")
MultiColumnComboBox1.AddItem("EmpCode1,EmpName1")
MultiColumnComboBox1.AddItem("EmpCode2,EmpName2") MultiColumnComboBox1.LoadData()
MultiColumnComboBox1.Dock = DockStyle.Fill
End Sub
'AS we click on DatagRid COlumn 1 The MultiColumn ComboBox
'Should Populate & displayed
Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown
Try
hitTestGrid = Me.DataGrid1.HitTest(e.X, e.Y)
If Not (hitTestGrid Is Nothing) Then
datagridtextBox.TextBox.Controls.Add(MultiColumnCo mboBox1)
MultiColumnComboBox1.Cursor = Cursors.Arrow
MultiColumnComboBox1.BringToFront()
MultiColumnComboBox1.Visible = True End If
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
But When I m using this MultiCOlumn Combo Control on form
It works fine It shows proper Columns with data
But when I put it into my datagrid it will not work.
Conclusion may b:
User Controls can't be added inside datagridtextboxCOlumn
Plz reply me any link,direction,suggestion as its very urgent for me.
Thanks & Regards
Hema Chaudhry
|

January 3rd, 2006, 12:26 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
The problem is that you have declared a single control on your form. However, the datagrid wants to draw more than one and will not map all of them to a single instance on the form. Therefore you need to execute the block of code that deals with the control for each item (row) in the datagrid. I do this all the time with the ASP.NET datagrid, but I have not worked with the WinForms datagrid so I can't provide much more than that.
Here's the MSDN help for the winforms datagrid class:
http://msdn.microsoft.com/library/en...ClassTopic.asp
- Peter
|

January 4th, 2006, 05:04 AM
|
Registered User
|
|
Join Date: Jan 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Really Thanks for the reply,
I have seen the link u suggested.
But I have already done that in code:
Adding Custom columns to datagrid.
colStyle = Me.DataGrid1.TableStyles(0).GridColumnStyles
colStyle(0).Width = 100
colStyle(1).Width = 150
colStyle(2).Width = 100
colStyle(3).Width = 180
colStyle(0).Alignment = HorizontalAlignment.Center
colStyle(1).Alignment = HorizontalAlignment.Center
colStyle(2).Alignment = HorizontalAlignment.Center
colStyle(3).Alignment = HorizontalAlignment.Center
End If
The problem is Dropdown list is displayed in the Datgrid Column
But there is no data inside Combobox Even that combo is not drop dwon
But when i try it on form then that combo will work fine (Display multi columns as well shows items at drop down)
But i m not able to get why is it not working inside datagrid text box column.???????????????
Thanks a lot
Plz Help?
Thanks & Regards
Hema Chaudhry
|

January 4th, 2006, 11:55 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
When you put the control on the form, there is only 1 instance of it. You have an explicit name for that control, and are therefore able to manipulate its properties.
When you put the control in a column of a grid it will need to exist multiple times, once for each row in the grid. Therefore you can NOT reference it with an explicit name and thus you can not manipulate its properties by a name. You'll need to find some way to get at the cell where the control lives for EACH row in the grid so you can manipulate each control separately.
- Peter
|

October 29th, 2006, 10:30 PM
|
Authorized User
|
|
Join Date: Oct 2006
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Hemachaudhry,
I also want to create a multicolumncomboxbo but I can't.
You write:
"Private WithEvents MultiColumnComboBox1 As New MultiColumnComboBox.MultiColumnComboBox "
I'm using vb.net2005.
How can I declare a MultiColumnComboBox?
Thanks in advance.
|
|
 |