all groups > c# > february 2006 >
You're in the

c#

group:

DataGrid custom styles


DataGrid custom styles Peter
2/28/2006 11:18:24 PM
c#:
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


Thank You


Peter

RE: DataGrid custom styles jetan NO[at]SPAM online.microsoft.com (
3/1/2006 12:00:00 AM
Hi Peter,

Thanks for your post!

I have given a look to this issue. It seems that the author implemented
IBindingList interface to perform the customized databinding.

To support column style, DataGrid first get the CurencyManager, then it
will try to use CurencyManager.GetListName property to get the MappingName
of the TableStyle. However, the CurencyManager.GetListName internally
queries ITypedList interface of the underlying datasource, and returns
ITypedList.GetListName. So we should modify ArrayDataView implementation to
implement ITypedList interface.

Also, DataGrid compares PropertyDescriptor.Name with
DataGridColumnStyle.MappingName property to create the columns. So in
ArrayPropertyDescriptor implementation, we should also override
PropertyDescriptor.Name property and returns corresponding column name.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Re: DataGrid custom styles Peter
3/1/2006 8:09:54 AM

[quoted text, click to view]

Thank you very much for all the time you have spent on this, I will try your
suggestion, but I might be back.


Re: DataGrid custom styles jetan NO[at]SPAM online.microsoft.com (
3/2/2006 2:02:03 AM
Ok, if you still have anything unclear, please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Re: DataGrid custom styles Peter
3/19/2006 11:41:31 PM

[quoted text, click to view]


I have implemented the ITypeList, but what do I return for
PropertyDescriptorCollection and GetListName

I am using http://www.codeproject.com/cs/database/BindArrayGrid.asp

#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

AddThis Social Bookmark Button