本文介绍了对datagrid的帮助很小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好。 我还在学习曲线......从我读到的内容,我创建了 继承的datagrid类所以我可以在我的数据网格的 列中有图标,组合框等。 网格将用于填充来自Web服务的信息。 (没有 数据集 - 没有数据加载器。) 所以,我不知道如何使用数据源。 现在我差不多了...但是我需要一些帮助才能以编程方式填充数据网格。 这是, (我希望)我使用的是一个简短的代码。我创建了一个包含3列的网格。 第1列是一个带有文本+图标的列,名为DataGridIconTextColumn 继承自同名的类。 第2列是一个带有图标的列,名为DataGridIconOnlyColumn,从同名的类继承 。取决于一些标志和标志。我将使用1 图标或其他。 第3列是常规DataGridTextBoxColumn ''从嵌入式资源中加载一些图标 Me.Icons = New ImageList Dim iconName As String iconName =" datagridicons.user.ico" Dim strm As System.IO.Stream strm = Me.GetType.Assembly.GetManifestResourceStream(icon name) Dim icon As Icon icon =新图标(strm) Me.Icons.Images.Add(icon.ToBitmap) iconName =" datagridicons.IconUser1.ico" strm = Me.GetType.Assembly.GetManifestResourceStream(图标名称) icon =新图标(strm) Me.Icons.Images.Add(icon.ToBitmap) iconName =" datagridicons.IconUser2.ico" strm = Me.GetType.Assembly.GetManifestResourceStream(icon name) icon = New图标(strm) Me.Icons.Images.Add(icon.ToBitmap) Dim tableStyle As DataGridTableStyle tableStyle =新DataGridTableStyle tableStyle.MappingName =" customers" Dim numCols As Integer numCols = 3 Dim iconColumn As DataGridIconTextColumn iconColumn = New DataGridIconTextColumn(Me.Icons,New delegateGetIconIndexForRow(AddressOf) MyGetImageIndexForRow)) iconColumn.HeaderText =" headercolumn1" iconColumn.MappingName =" headercolumn2" tableStyle.GridColumnStyles.Add(iconColumn ) Dim iconColumn2 As DataGridIconOnlyColumn iconColumn2 = New DataGridIconOnlyColumn(Me.Icons,New delegateGetIconIndexForRow(AddressOf MyGetImageIndexForRow)) iconColumn2.HeaderText ="" iconColumn2.MappingName =" Icon" iconColumn2.Width = Me.Icons.Images(0 ).Size.Width tableStyle.GridColumnStyles.Add(iconColumn) Dim aColumnTextColumn As DataGridTextBoxColumn aColumnTextColumn = New DataGridTextBoxColumn aColumnTextColumn.HeaderText =" headercolumn3" aColumnTextColumn.MappingName =" headercolumn3" tableStyle.GridColumnStyles.Add(aColumnTextColumn) ''使dataGrid使用我们的新tablestyle并将其绑定到我们的 表 dataGrid1.TableStyles.Clear() dataGrid1.TableStyles.Add(tableStyle) 现在,使用一个循环(例如i = 0到5 ......等等) ),有人可以告诉我 如何填充网格? 非常感谢您提前 解决方案 Hello everybody I''m still on the learning curve here...and from what I read, I createdinherited datagrid class so I could have icons, combobox...etc in thecolumns of my datagrid. The grid will be used to populate information coming from a Webservice. (Nodatasets - No datareaders).So, I do not know see how to use the "datasource". Now I''m almost there...but I would need a little bit of help toprogramatically populate the datagrid. Here is , (I hope) a short code that I use. I create a grid with 3 columns.the column 1 is a column with text + icon called DataGridIconTextColumninherited from the class of the same name.the column 2 is a column with icon called DataGridIconOnlyColumn inheritedfrom the class of the same name. Depending on some "flag" I will be using 1icon or another.The column 3 is a regular DataGridTextBoxColumn''load some icons from embedded resourcesMe.Icons = New ImageListDim iconName As StringiconName = "datagridicons.user.ico"Dim strm As System.IO.Streamstrm = Me.GetType.Assembly.GetManifestResourceStream(icon Name)Dim icon As Iconicon = New Icon(strm)Me.Icons.Images.Add(icon.ToBitmap)iconName = "datagridicons.IconUser1.ico"strm = Me.GetType.Assembly.GetManifestResourceStream(icon Name)icon = New Icon(strm)Me.Icons.Images.Add(icon.ToBitmap)iconName = "datagridicons.IconUser2.ico"strm = Me.GetType.Assembly.GetManifestResourceStream(icon Name)icon = New Icon(strm)Me.Icons.Images.Add(icon.ToBitmap) Dim tableStyle As DataGridTableStyletableStyle = New DataGridTableStyletableStyle.MappingName = "customers" Dim numCols As IntegernumCols = 3 Dim iconColumn As DataGridIconTextColumniconColumn = New DataGridIconTextColumn(Me.Icons, NewdelegateGetIconIndexForRow(AddressOf MyGetImageIndexForRow))iconColumn.HeaderText = "headercolumn1"iconColumn.MappingName = "headercolumn2"tableStyle.GridColumnStyles.Add(iconColumn) Dim iconColumn2 As DataGridIconOnlyColumniconColumn2 = New DataGridIconOnlyColumn(Me.Icons, NewdelegateGetIconIndexForRow(AddressOf MyGetImageIndexForRow))iconColumn2.HeaderText = ""iconColumn2.MappingName = "Icon"iconColumn2.Width = Me.Icons.Images(0).Size.WidthtableStyle.GridColumnStyles.Add(iconColumn) Dim aColumnTextColumn As DataGridTextBoxColumnaColumnTextColumn = New DataGridTextBoxColumnaColumnTextColumn.HeaderText = "headercolumn3"aColumnTextColumn.MappingName = "headercolumn3"tableStyle.GridColumnStyles.Add(aColumnTextColumn)'' make the dataGrid use our new tablestyle and bind it to ourtabledataGrid1.TableStyles.Clear()dataGrid1.TableStyles.Add(tableStyle)Now, using a loop (for instance for i = 0 to 5 ...etc), can somebody show mehow to populate the grid ?Thank you very much in advance 解决方案 这篇关于对datagrid的帮助很小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-29 17:48