Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / June 2005

Tip: Looking for answers? Try searching our database.

Display a matrix in a datagrid?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Cohagan - 06 Jun 2005 03:35 GMT
I've got an n x n matrix (of integers) that I'd like to display in a grid.
The matrix is actually wrapped in a class. What's the best approach for
binding the matrix to the grid? Currently I've implemented the IList
interface on my object, exposing the list of n^2 elements as a list, but
this just results in a grid with n^2 rows and a few columns displaying the
attributes of the cells in the grid. (Yes, I said integers, but in fact the
cells are objects that contain other information as well; e.g., row, col
numbers.)

So, perhaps what I want is to redo the IList to return a list of rows, but
then how do I handle the columns as far as binding to the grid columns? Any
suggestions/guidance would be appreciated.

Thanks in advance,
Bill
"Jeffrey Tan[MSFT]" - 06 Jun 2005 09:47 GMT
Hi Bill,

Thanks for your post.

For your requirement, we have several options to get it done.

1. We can dynamically create a n-Column int type DataTable, then add the
n^2 elements in the DataTable, then we can bind the DataTable to the
DataGrid. I think this is the simplest way.

2. What you wanted is similiar with the funciton DataTable and DataSet
class provided. Actually, DataTable and DataSet both implemented
IListSource interface, if you also want to enable internal Column
databinding to certain field, your class should implement IListSource
interface. You may view IListSource in MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemComponentModelIListSourceClassTopic.asp

However, this requires more work to be done. For more information, please
refer to:
"HOWTO: implement IListSource in Winforms v2"
http://noiseehc.freeweb.hu/IListSource.html

Hope this helps
===============================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Bill Cohagan - 07 Jun 2005 19:33 GMT
Jeffrey

 Thanks for the response. I didn't really find the msdn documentation on
IListSource very helpful. It read like it would be helpful if I already
understood how thing worked!  In any case I found a simpler way. Since in my
case there are a fixed number of cells in the matrix I ended up just using a
panel with 81 TextBox controls -- generated and placed at form load time. I
used the Observer Pattern to link up my cell objects with the corresponding
TextBox so that any change to the value of a cell would be reflected
immediately in the UI.

 Interestingly I found that letting my app run full speed resulted in no
update of the UI, presumably the messages were being genereated so quickly
that each message caused the previous to be ignored.  I vaguely remember
something about this message loop handling from some long ago reading about
Windows architecture. What I wanted to achieve was a visual reflection of a
game board tree search for the game of Sudoku. I finally got it to work by
inserting a call to Sleep() in my cell update code.

 One problem remains however. When the form is running you can watch the
tree search progress (and regress), but if I bring another application's
window in front of the form, then switch focus back to the form I find that
the visual update has stopped. Any idea what might cause that?

Thanks,
Bill

> Hi Bill,
>
[quoted text clipped - 30 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 08 Jun 2005 02:44 GMT
Hi Bill,

Thanks for your feedback.

First, I think there are too much details unclear in your implementation,
such as:
1. How you do the updating with the 81 textboxes from the matix data?
2. How you implement the "tree search progress", did you use
multi-threading in your App?

I suggest you provide some description of your application context, some
key code snippet will be helpful on the understanding of you scenario.

Additionally, does my first suggestion of copying the 9^2 matrix elements
into a DataTable, then bind this DataTable to the DataGrid make sense to
you? Because you have fixed number of elements, I think it is easy to
implement, then we can leverage Winform complex databinding for the 2 way
updating.

At last, for your last issue, I suggest you create a little sample project
to reproduce out the problem, then I can help you better on it. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

MichaelGeier - 29 Jun 2005 09:30 GMT
Hello Bill,
I have exact the same problem.
I want a 2d-Array as a DataSource for a DataGrid.
In the meantime, maybe you have solved this problem??

Michael

> I've got an n x n matrix (of integers) that I'd like to display in a grid.
> The matrix is actually wrapped in a class. What's the best approach for
[quoted text clipped - 11 lines]
> Thanks in advance,
>  Bill

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.