DataGrid Custom Styles

P

Peter

I am using ArrayDataView from the following link, my question is how do I
apply column styles to this DataGrid that uses ArrayDataView instead of
DataSet

http://www.codeproject.com/cs/database/BindArrayGrid.asp


I have tried the following code, but it has no effect

Private Sub CreateColumnStyles(ByVal grd As DataGrid)
Dim tableStyle As New DataGridTableStyle
Dim tableGrid As ArrayDataView = Nothing

Try

tableGrid = CType(grd.DataSource, ArrayDataView)
'
' Clear any existing table styles.
'
grd.TableStyles.Clear()
'
' Use mapping name that is defined in the data source.
'
tableStyle.MappingName = ""
'
' Now create the column styles within the table style.
'
Dim columnStyle As DataGridTextBoxColumn
Dim currCol As Integer
Dim colNames As String() = tableGrid.ColumnNames()

For currCol = 0 To tableGrid.Data.GetUpperBound(0) - 1

columnStyle = New DataGridTexBoxColumn
With columnStyle
.HeaderText = colNames(currCol)
.MappingName = colNames(currCol)
.NullText = ""
End With
'
' Add the new column style to the table style.
'
tableStyle.AlternatingBackColor =
System.Drawing.Color.Lavender
tableStyle.GridColumnStyles.Add(columnStyle)
Next currCol
'
' Add the new table style to the data grid.
'
grd.TableStyles.Add(tableStyle)
Catch e As Exception
MessageBox.Show(e.Message)
End Try
End Sub



I have implemented the ITypeList in the ArrayDataView , but what do I return
forom
PropertyDescriptorCollection and GetListName


#region ITypedList Members

public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[]
listAccessors)
{
// TODO: Add ArrayDataView.GetItemProperties implementation
return null;
}

public string GetListName(PropertyDescriptor[] listAccessors)
{
// TODO: Add ArrayDataView.GetListName implementation
return null;
}

#endregion


Thank You


Peter
 
C

Cor Ligthert [MVP]

Peter,

I think that you would ask that to Mihail.

The datagrid is not that control that is made to use with every collection
class. One of the advantages of the DataGridView should be that this has
more posibilities in this.

Cor
 
J

Jeffrey Tan[MSFT]

Hi Peter,

Thanks for your post!

We can return a meaningful string for GetListName() method. Regarding
GetItemProperties() method, it requires some extra work to be done. You can
get some information regarding implementing this interface from the
articles below:
http://noiseehc.freeweb.hu/IListSource.html
http://www.freeweb.hu/noiseehc/DS.cs
"Really complex databinding: ITypedList with weakly typed collections "
http://weblogs.asp.net/fbouma/articles/115837.aspx

You may give this a try. However, I agree with "Cor Ligthert [MVP]" that
because we are not the author of the article, you'd better contact the
article author for the help regarding his article.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
K

Ken Tucker [MVP]

Peter,

In addition to the other comments. To use a table style with a
datagrid bound to an arraylist use arraylist as the tablestyles mapping
name. For collection use collection as the mapping name. A blank mapping
name will never work. I would try ArrayDataView for the mapping name.

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top