|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Newbie; datagrid and Excel questionsHi,
I have the following two questions: 1) Is there a way to customize the titles of the columns in the datagrid or does it have to be the names coming from the db tables`columns. I want to avoid having to show CIid for example, i prefer to rename it to Customer ID, etc. I went over the datagrid formatting properties without success. 2) Does anyone have any suggestions for an introductory article regarding creating Excel files through VB.net ? I would like to eventually, give the user the choice to not only see the data in the datagrid but also to save them in Excel file(s). BTW is datagrid the best solution for ``static`` data? i.e. data that only needs to be displayed and not modified in any way. TIA and my apologies for the many questions -steve 1)
'clear the table styles [yourgridnamewithoutthebrackets].TableStyles.Clear() 'create a newone ts1 = New DataGridTableStyle ts1.AlternatingBackColor = GridAltBGColor 'map to whatever in your db ts1.MappingName = "tblProperty" 'this is a sample of calling a routine, I made to add the db fieldname and then display name to 'the style (you would call it once for each field AddTextBoxColumnToGrid(ts1, "Case_ID", "Case ID", 0) I wrote the following routine to help me create DataGridTextBoxColumn objects and add them to the DataGridTableStyle which is how you do what you are wanting to do. feel free to use the routine below but give me credit 'AddTextBoxColumnToGrid: To assist in making column styles and add to datagridtablestyle Friend Sub AddTextBoxColumnToGrid(ByRef objDataGridTableStyle As DataGridTableStyle, _ ByVal dbFieldName As String, _ ByVal ColText As String, _ Optional ByVal ColWidth As Integer = 15, _ Optional ByVal ColAlignment As HorizontalAlignment = HorizontalAlignment.Left, _ Optional ByVal ColFormat As String = "", _ Optional ByVal MaxLength As Integer = -1) Dim objTextCol As New DataGridTextBoxColumn 'set mapping name objTextCol.MappingName = dbFieldName objTextCol.HeaderText = ColText objTextCol.Width = ColWidth objTextCol.Alignment = ColAlignment If ColFormat.Length > 0 Then objTextCol.Format = ColFormat If MaxLength > 0 Then objTextCol.TextBox.MaxLength = MaxLength 'add col to grid style objDataGridTableStyle.GridColumnStyles.Add(objTextCol) End Sub This should at least get you started. Another option: "SELECT CIid as [Customer ID] so that you alias the field to be whatever you want to show...this is the re al simple way...but you still don't have the formatting capabilities that you do with creating styles. 2.) Probably google the subject. HTH, shane Show quoteHide quote "steve" <st***@here.com> wrote in message news:rqh3e.50814$rl.840564@weber.videotron.net... > Hi, > I have the following two questions: > > 1) Is there a way to customize the titles of the columns in the datagrid or > does it have to be the names coming from the db tables`columns. I want to > avoid having to show CIid for example, i prefer to rename it to Customer ID, > etc. I went over the datagrid formatting properties without success. > > 2) Does anyone have any suggestions for an introductory article regarding > creating Excel files through VB.net ? I would like to eventually, give the > user the choice to not only see the data in the datagrid but also to save > them in Excel file(s). > > BTW is datagrid the best solution for ``static`` data? i.e. data that only > needs to be displayed and not modified in any way. > > TIA and my apologies for the many questions > -steve > >
sorting files retrieved by OpenFileDialog
Total seconds of day VB.Net Joining Paradox and SQL Server Table? Insert Border around a picture MDI Child Form ? Using Comm dll file in vb.net 2003 error Read private variables between forms touch screen monitors Terminating a thread Resize Tab control when windows form resizes |
|||||||||||||||||||||||