DataGrid Complex Binding

K

K

I created a collection which is derived from ArrayList and implements
IBindingList and ITypedList.

Then I bound the DataSource of a data grid into the collection. It could
show up the data but the column heading is not in the right order, for eg. I
want "ID" column to be the first column but it showed as the second column.

Another problem is that anyway i can leave a blank row in the grid to add a
new row automatically if the user selected and tyepd something there ?

Thanks
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hello,

To define which columns are visible and in what order, you will need to
create a custom System.Windows.Forms.DataGridTableStyle with a set of
System.Windows.Forms.DataGridColumnStyle-s.

The availability of the blank row at the bottom is controlled by the
AllowNew property of the IBindingList interface. As far as I remember,
returning "true" will result in this row being displayed.
 
K

K

Thanks so much for your quick resonse. I'll try DataGridColumnStyle, but for
AllowNew matter, my collection class is returning true for
IBindingList.AllowNew, and the blank row doesn't show up too.

Dmitriy Lapshin said:
Hello,

To define which columns are visible and in what order, you will need to
create a custom System.Windows.Forms.DataGridTableStyle with a set of
System.Windows.Forms.DataGridColumnStyle-s.

The availability of the blank row at the bottom is controlled by the
AllowNew property of the IBindingList interface. As far as I remember,
returning "true" will result in this row being displayed.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

K said:
I created a collection which is derived from ArrayList and implements
IBindingList and ITypedList.

Then I bound the DataSource of a data grid into the collection. It could
show up the data but the column heading is not in the right order, for
eg.
I
want "ID" column to be the first column but it showed as the second column.

Another problem is that anyway i can leave a blank row in the grid to
add
a
new row automatically if the user selected and tyepd something there ?

Thanks
 
D

Dmitriy Lapshin [C# / .NET MVP]

You're welcome. You can also ensure this (quoted from the MSDN Library):

-------------------
Remarks
If IList.IsFixedSize or IList.IsReadOnly is true, this property returns
false.
-------------------

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

K said:
Thanks so much for your quick resonse. I'll try DataGridColumnStyle, but for
AllowNew matter, my collection class is returning true for
IBindingList.AllowNew, and the blank row doesn't show up too.

Dmitriy Lapshin said:
Hello,

To define which columns are visible and in what order, you will need to
create a custom System.Windows.Forms.DataGridTableStyle with a set of
System.Windows.Forms.DataGridColumnStyle-s.

The availability of the blank row at the bottom is controlled by the
AllowNew property of the IBindingList interface. As far as I remember,
returning "true" will result in this row being displayed.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

K said:
I created a collection which is derived from ArrayList and implements
IBindingList and ITypedList.

Then I bound the DataSource of a data grid into the collection. It could
show up the data but the column heading is not in the right order, for
eg.
I
want "ID" column to be the first column but it showed as the second column.

Another problem is that anyway i can leave a blank row in the grid to
add
a
new row automatically if the user selected and tyepd something there ?

Thanks
 
K

K

My collection is derived from ArraryList, and I checked from MSDN, the
default for IList.IsReadOnly and IList.IsFixedSize are both "false". In my
collection, the IBindingList.AllowEdit, IBindingList.AllowRemvoe and
IBindingList.AllowNew are both true. But, DataGrid still didn't show up the
blank row for me to create a new row.

For the row column ordering, I tried to add TabeStyles in design time called
"headerStyle" and in it, i added two DataGridColumnStyles,
1. Header Text -> "Choices" , Mapping Name -> "ID"
2. Header Text -> "Wording", Mapping Name -> "Wording"

where ID and Wording are the actual properties in my contained objects.

Is it because I bind the datasource at run time to my collection, so the
headers didn't show up correctly ??

I got one more confused. What should i put in Mapping Name for my Table
Style "headerStyle" ? ( I just leave it blank now )



Dmitriy Lapshin said:
You're welcome. You can also ensure this (quoted from the MSDN Library):

-------------------
Remarks
If IList.IsFixedSize or IList.IsReadOnly is true, this property returns
false.
-------------------

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

K said:
Thanks so much for your quick resonse. I'll try DataGridColumnStyle, but for
AllowNew matter, my collection class is returning true for
IBindingList.AllowNew, and the blank row doesn't show up too.

in message news:[email protected]...
Hello,

To define which columns are visible and in what order, you will need to
create a custom System.Windows.Forms.DataGridTableStyle with a set of
System.Windows.Forms.DataGridColumnStyle-s.

The availability of the blank row at the bottom is controlled by the
AllowNew property of the IBindingList interface. As far as I remember,
returning "true" will result in this row being displayed.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

I created a collection which is derived from ArrayList and implements
IBindingList and ITypedList.

Then I bound the DataSource of a data grid into the collection. It could
show up the data but the column heading is not in the right order,
for
eg.
I
want "ID" column to be the first column but it showed as the second
column.

Another problem is that anyway i can leave a blank row in the grid
to
add
a
new row automatically if the user selected and tyepd something there ?

Thanks
 
D

Dmitriy Lapshin [C# / .NET MVP]

My collection is derived from ArraryList, and I checked from MSDN, the
default for IList.IsReadOnly and IList.IsFixedSize are both "false". In my
collection, the IBindingList.AllowEdit, IBindingList.AllowRemvoe and
IBindingList.AllowNew are both true. But, DataGrid still didn't show up the
blank row for me to create a new row.

To be honest, I have no idea. It is of course virtually possible that
DataGrid has a hard-coded type check, and if the type is not DataTable or
DataView, the "new" row never appears, but how one can find it out?
Is it because I bind the datasource at run time to my collection, so the
headers didn't show up correctly ??

You should create DataGridTableStyle/DataGridColumnStyle before binding the
data source. You should also use the SetDataBinding method.
I got one more confused. What should i put in Mapping Name for my Table
Style "headerStyle" ? ( I just leave it blank now )

I think its value should be equal to the grid's DataMember property value.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

K said:
My collection is derived from ArraryList, and I checked from MSDN, the
default for IList.IsReadOnly and IList.IsFixedSize are both "false". In my
collection, the IBindingList.AllowEdit, IBindingList.AllowRemvoe and
IBindingList.AllowNew are both true. But, DataGrid still didn't show up the
blank row for me to create a new row.

For the row column ordering, I tried to add TabeStyles in design time called
"headerStyle" and in it, i added two DataGridColumnStyles,
1. Header Text -> "Choices" , Mapping Name -> "ID"
2. Header Text -> "Wording", Mapping Name -> "Wording"

where ID and Wording are the actual properties in my contained objects.

Is it because I bind the datasource at run time to my collection, so the
headers didn't show up correctly ??

I got one more confused. What should i put in Mapping Name for my Table
Style "headerStyle" ? ( I just leave it blank now )



Dmitriy Lapshin said:
You're welcome. You can also ensure this (quoted from the MSDN Library):

-------------------
Remarks
If IList.IsFixedSize or IList.IsReadOnly is true, this property returns
false.
-------------------

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

K said:
Thanks so much for your quick resonse. I'll try DataGridColumnStyle,
but
for
AllowNew matter, my collection class is returning true for
IBindingList.AllowNew, and the blank row doesn't show up too.

in message Hello,

To define which columns are visible and in what order, you will need to
create a custom System.Windows.Forms.DataGridTableStyle with a set of
System.Windows.Forms.DataGridColumnStyle-s.

The availability of the blank row at the bottom is controlled by the
AllowNew property of the IBindingList interface. As far as I remember,
returning "true" will result in this row being displayed.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

I created a collection which is derived from ArrayList and implements
IBindingList and ITypedList.

Then I bound the DataSource of a data grid into the collection. It could
show up the data but the column heading is not in the right order, for
eg.
I
want "ID" column to be the first column but it showed as the second
column.

Another problem is that anyway i can leave a blank row in the grid to
add
a
new row automatically if the user selected and tyepd something
there
 

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