DataTable and MDI form problems in VB.Net 2003

Hi all,

I will be really happy if someone could help me with a problem that has been causing me heartache for about a year.

From an MDI parent I want to directly access the contents of a DataTable that is in an MDI child that is only singled out by its caption text.

In the parent I figure out which MDI child I want by counting over Me.MdiChildren.Length while comparing its Text with the caption I am looking for. I then find the Janus Grid that is in the MDI child that the DataTable is bound to. I then get the data through the grid control but the grid "conditions" the data depending on how it is sorted.

I can't seem to figure out how to get the data directly and so, as a workaround I get it through the grid which is messy and counterproductive.

Can anyone please Help

 

Justine

 




Answer this question

DataTable and MDI form problems in VB.Net 2003

  • htayhlaing_win

     Justine wrote:
    "System.Windows.Forms.CurrencyManager"

    good.. we are getting there!

    try this:

    Dim ctxt as object = ChildGridEX.BindingContext(ChildGridEX.DataSource)
    Dim cm as CurrencyManager = CType(ctxt, CurrencyManager)
    MessageBox.Show(cm.List.GetType().ToString())

    what does that dialog show you. . .

    A little trick  [ctrl]+c will copy the Dialog to the clip board so you can quickly paste it here.

     Justine wrote:
    Ok, a female point of view - when my computer updates itself automatically - why do I have to stop what I'm doing and reboot

    Whaddya think this is Linux geez!!!



  • Ori Amiga - MSFT

    Ok, I get

    "System.Windows.Forms.CurrencyManager"

    My problem is that currently ChildGridEX is the data in the grid, not the data that the grid is looking at. The grid allows me to group data but then ChildGridEX has blank rows from the grouping. The grid allows me to "hide" stuff I don't want but then I can't get to this data at all.

    I am female and actually I was programming since I was 12 when dad got me my laptop. He also got me visual basic to get me off his computer. The program I am writing is for getting data from a pic which is really cool. The data will be in the grid and the parent has code to limit rows and columns in the grid so I don't get swamped with numbers.

    Ok, a female point of view - when my computer updates itself automatically - why do I have to stop what I'm doing and reboot

    Justine

     

     

     



  • rbfigueira

    It doesn't work!

    I get a wiggly line under cm.List.GetType().ToString()

    and

    the tooltiptext on the error is 'GetType' is not a member of 'System.Collections.IList'

    Most of my teachers think that one of the sciences is what I really need but right now I'm just having fun getting some of my ideas working

    I've got to go for about 30 minutes - dad has made some dinner

     

    see ya



  • lbsjs2005

     Blair Allen Stark wrote:

    So the BindingContext->CurrencyManager->List->DataView works, eh mark it as an answer!

    oops. . . you meant my ctrl+c tip worked!

    ok. . . we got the DataView! Lets bring it on home!

    Dim ctxt as object = ChildGridEX.BindingContext(ChildGridEX.DataSource)
    Dim cm as CurrencyManager = CType(ctxt, CurrencyManager)
    Dim dv as DataView  = CType(cm.List, DataView)
    Dim dt as DataTable = dv.Table

    There you go!

    (Now you can mark it as the answer!)



  • slantednet

     Justine wrote:
    Ok - to answer your questions, I did read the Screwtape Letters but I had to research it a bit because it went over my head - I'm not from a Christian background and that was the book's focus. I thought it was neat how the big demon gets the little demon to convince the human to pray to a corner of the room instead of his god.
    My favorite is when the demon says with regard to the human dealing with his mother (could apply to friends and lovers, too):

    In clivilized life domestic hatred usually epresses itself by saying things which would appear quite harmless on paper (the words are not offensive) but in such a voice, or at such a moment, that they are not far short of a blow in the face. To keep this game up . . . see to it that each of these two fools has a sort of double standard. Your patient must demand that all his own utterances are to be taken at face value and judged simply on the actual words, while at the same time judging all his mothers utterences with the fullest and most over-sensitive interpretation of the tone and the context and the suspected intention. Hence from every quarrel they can both go away convinced, or very nearly convinced that they are quite innocent.

    And where the demon talks about keeping the humans prayer focused on trying to induce a particular feeling so when it fails, as it most surely will, he will distrust the entire process.

    Just pick up the book on a random day, open to a random page and it is hard not to say to yourself "Man, I was thinking that way a few minutes ago!"

     Justine wrote:
    Don't code to live and live to code; explore a different dicipline and marry programming and the other.
    bingo! Slamming Techno! computers and music!  

     Justine wrote:
    I'm trying to get my programs to be flexible enough to do my data aquisition for me (probably because I'm too lazy to do it myself).
    Ah Justine, you will be one fine software engineer! But not at the exclusion of discipline!!! Disciplined Laziness is the mark of Excellence.

     Justine wrote:
    King Kong was absolutely fantastic - I won't tell you the ending but I really liked it!!!
    There was a joke there. . . I swear there was

    "Don't tell me how Titanic or The Passion of The Christ ends. . . I want to be surprised."

     Justine wrote:
    Calculus is really cool but I have only done a little differential equation exercise; I can see myself being lost in pure mathermatics because I have a compulsive personality.
    Did I mention you are gonna make a fine Software engineer.

     Justine wrote:
    I'm trying to figure out what you have done - ctxt is set to whatever the ChildGridEX is bound to but you don't know so its just "object", CM is then set to a CurrencyManager - a more flexible variable than ctxt's "object". The CType forces cm as a DataView and the DataView contains the DataTable that I want. Is that the explanation - there are variable types I don't have a clue about here I'll have a look in the morning.
    Bingo! You can think of a computers memory a a rolled out flattened piece of dough. What the CType does is called a "cast." What we are doing in this process is  "Starting at this point in the dough, we know we have some object. Lets put a CurrencyManager cookie cutter on it. Now we can see its list object. Lets put a DataView cookie cutter on that and now we can see its DataTable object." This paradigm is more direct in other languages such as C#, C++ and delphi where you just do this:

    DataTable dt as  =( (ChildGridEX.BindingContext[ChildGridEX.DataSource] as CurrencyManager) .List as DataView).Table; 

    or

    DataTable dt as  = ((DataView) ((CurrencyManager) ChildGridEX.BindingContext[ChildGridEX.DataSource]).List).Table; 

     Justine wrote:
    Also, if I have created a copy of the GridEX and then copied that data into a number of other variables that could take up lots of space in memory, isn't it possible to destroy the variables dv, cm, ctxt and the ChildGridEX by setting them to nothing

    First, in .Net, you don't have to set them to nothing as when they go out of scope they will be automatically "garbage collected" (look up "garbage collection") . Note: If you created them via a "New" statement, you should dispose them. But you didn't so don't. 

    Second, you didn't copy them, you created a reference to them. If you and I both point at a coffee cup, we both have a reference to the coffee cup, but there is still only one coffee cup. . . right Wouldn't it be cool if we could point at a CLS55 AMG  and instantly have a copy  But, alas, the world doesn't work that way.

    Take a look at Reference Types and Value Types.

    Help is your friend as is Wiki.

    Cheers!



  • Karpov Andrey

    That's ok - pobodys nerfect ;)

     

    ---------------------------

    ---------------------------
    System.Data.DataView
    ---------------------------
    OK  
    ---------------------------

    Hey, cool - your tip above, it worked!

    I have already done about all the trigonometry that my brain can hold and dad got me this year's texts early but the maths is a little lame - I already know some calculus and matrixes but it is really the applied stuff that I like, stuff to do with lenses and acoustics and colours in rainbows. I like analog and digital electronics as well even though digital tends to be more sloppy.

    I also read a lot, thats probably why I didn't like War of the Worlds but did like The Lion, The Witch and the Waredrobe - big budget movies should hold vaguely to the book.

    What do you get up to when you aren't answering forum questions

    This might be my last post for today - I'm going out tonight! We are watching King Kong!

    Justine



  • Neil Cowburn - MVP

    Hi Blair,

    I have just sneaked back in and couldn't wait to take a peek at your reply and I got two!

    Ok - to answer your questions, I did read the Screwtape Letters but I had to research it a bit because it went over my head - I'm not from a Christian background and that was the book's focus. I thought it was neat how the big demon gets the little demon to convince the human to pray to a corner of the room instead of his god.

    Don't code to live and live to code; explore a different dicipline and marry programming and the other. I'm trying to get my programs to be flexible enough to do my data aquisition for me (probably because I'm too lazy to do it myself). This means I can get into electronics as well. I always try and apply something I figure out - I hear and I forget, I see and I remember, I do and I understand.

    King Kong was absolutely fantastic - I won't tell you the ending but I really liked it!!!

    Calculus is really cool but I have only done a little differential equation exercise; I can see myself being lost in pure mathermatics because I have a compulsive personality.

    I'm trying to figure out what you have done - ctxt is set to whatever the ChildGridEX is bound to but you don't know so its just "object", CM is then set to a CurrencyManager - a more flexible variable than ctxt's "object". The CType forces cm as a DataView and the DataView contains the DataTable that I want. Is that the explanation - there are variable types I don't have a clue about here I'll have a look in the morning.

    Also, if I have created a copy of the GridEX and then copied that data into a number of other variables that could take up lots of space in memory, isn't it possible to destroy the variables dv, cm, ctxt and the ChildGridEX by setting them to nothing

    Good night and thanks till I test it out.

    Justine



  • NL Camp

    oops!

    sorry. . . just spitting code without testing. . .

    Dim ctxt as object = ChildGridEX.BindingContext(ChildGridEX.DataSource)
    Dim cm as CurrencyManager = CType(ctxt, CurrencyManager)
    Dim obj as Object = cm.List
    MessageBox.Show(obj.GetType().ToString())

    what does that get you

    Science is cool, but  how's your math



  • BqSoftware

    Hi Blair,

     

    Thanks for your really fast reply, but I'm having a few problems implementing it.

    What I have currently are two variables that hold which child to use and which control to get the data from. The command I use is like this :

    Dim ChildGridEX As GridEX = Ctype(Me.MdiChildren(intChild).Controls(intControl), GridEX)

    This gives me a copy of the control in the parent as it is in the child and then I can just get the data by using the commands that the control gives me.

    The CurrencyManager solution above doesn't seem to let me look at a child, if I use Me.MdiChildren(intChild).Controls(intControl) instead of Me.AGrid I can't get BindingContext in the little pull down. Maybe you forgot that the Grid is in a child and I want access to the data from the parent.

    BTW, I'm only 14 so maybe I've got it wrong from the start

    Any ideas

    Justine



  • Mark Dahl

     Justine wrote:
    You solution works! Thanks very much - I really appreciate the time you put into my problem, I couldn't have done it without you.
    You're welcome! Don't forget to mark the answer!
     Justine wrote:
    I went to a church once and it seemed shallow compared to what Lewis or Tolkien or Edison wrote. Just my opinion.
    Well don't judge all churches/faiths by a single, uninspired exposure. . . that would be shallow.
     Justine wrote:
    I like your quote because it shows how two faced society is
    Actually, I find the passage to warn against going through life expecting, even demanding, consideration and understanding when one is not willing to offer the same to others.

     Justine wrote:
    if I ask a teacher for help and the answer sounds vague, chances are the teacher doesn't know and society requires me not to question that. If I ask dad a question and he doesn't know - he tells me but also works out how we can find the answer. Maybe it has to do with insecurities or something.
    Or maybe your question wasn't clear. . . by all means, DO question your teachers!

     Justine wrote:
    I don't get what you said about King Kong
    Anyone my age knows that in the end "twas beauty that killed the beast"

     Justine wrote:
    Thanks for explaining the CType - so "casting" makes an object of a type that we may or may not know or even care about into something else that in the process offers a desired option in the process And you picked CurrencyManager because it seems to be able to hold almost any object. Is that right
    Sorry. . . no bingo here!!!

    I should have been more clear. . . I should have said - "Starting at this point in the dough, we know we have a CurrencyManager object." No, you can't cast any object to any other object. You can only cast an object to a more specific object if the object actually is one of those objects. We knew the Grid was bound to a DataTable. When bound to a datatable we know that BindingContext will return a CurrencyManager and the List will be a DataView. If the grid were bound to an ArrayList, the List would have been and ArrayList and casting as a DataView would have thrown an InvalidCast Exception. Again, look in the help at BindingContext and Currency Manager. 

     Justine wrote:
    Thanks for pointing out the cup of coffee and Mercedes analogy - the world would be really weird if everyone had one (but nicer).
    but void of ambition, eh

     Justine wrote:
    Ok - what about other questions I have - do I start a new thread and hope you visit me
    Yep start a new thread for another question and don't forget to mark the answer.

    and happy coding to you!

    b.



  • arby10101

     Justine wrote:
    I also read a lot, thats probably why I didn't like War of the Worlds but did like The Lion, The Witch and the Waredrobe - big budget movies should hold vaguely to the book.
    Have you read Lewis' The Screwtape letters Thats a fun book!

     Justine wrote:
    What do you get up to when you aren't answering forum questions

    "Code to live. . . live to code!"  Believe it or not. . . this is how I learn!

     Justine wrote:
    This might be my last post for today - I'm going out tonight! We are watching King Kong!

    Don't tell me how it ends!!!

    So the BindingContext->CurrencyManager->List->DataView works, eh mark it as an answer!

    BTW. . . Calc rocks!

    and Diff Eq's is the hand of God!

    Cheers!



  • Brian Leech

    Hi Blair,

    You solution works! Thanks very much - I really appreciate the time you put into my problem, I couldn't have done it without you.

    Ok, getting down to what you typed. I think that C.S. Lewis wrote to a different time or person that is here today; the Screwtape Letters and Narnia seem to have deeper content than what is in use today. I went to a church once and it seemed shallow compared to what Lewis or Tolkien or Edison wrote. Just my opinion.

    I like your quote because it shows how two faced society is; if I ask a teacher for help and the answer sounds vague, chances are the teacher doesn't know and society requires me not to question that. If I ask dad a question and he doesn't know - he tells me but also works out how we can find the answer. Maybe it has to do with insecurities or something.

    Ok - you want to marry computers with techno music, I like that - how about an MP3 player that slides two songs together by synchronising their beat automatically

    I think I was harsh on myself for calling myself lazy above - I am willing to do study and work but if something is repedative on a computer, shouldn't people be looking for a simpler way of doing the task and looking at the remaining problems by exception - this that a right way of saying this

    I don't get what you said about King Kong - BTW, the whole movie was fantastic, not just the ending - Oops!

    Thanks for explaining the CType - so "casting" makes an object of a type that we may or may not know or even care about into something else that in the process offers a desired option in the process And you picked CurrencyManager because it seems to be able to hold almost any object. Is that right

    Thanks for pointing out the cup of coffee and Mercedes analogy - the world would be really weird if everyone had one (but nicer).

    Ok - what about other questions I have - do I start a new thread and hope you visit me

    Thanks once again and happy coding,

    Justine



  • Paul Scheremet

    In gawd awful vb:

        Dim mngr as CurrencyManager = _  
                          CType(Me.AGrid.BindingContext(  _ 
                          Me.AGrid.DataSource), CurrencyManager)
        Dim dv as DataView = CType(mngr.List, DataView)

    in nice and clean c#:

        CurrencyManager mngr = (CurrencyManager)  
                         this.AGrid.BindingContext[this.AGrid.DataSource];
        DataView dv = (DataView)mngr.List;

    You can then work off of the DataView.

    Also, take a look at CurrencyManager. . . Many things are there that may be of interest. 

    This has become much more straight forward in .Net 2.0 as the binding model has changed.

     



  • Darren Gosbell

    Ok. . .

    Dim ChildGridEX As GridEX = Ctype(Me.MdiChildren(intChild).Controls(intControl), GridEX)

    gets the grid you want, correct

    If so, tell me what this dialog shows you:

    Dim ctxt as object = ChildGridEX.BindingContext(ChildGridEX.DataSource)

    MessageBox.Show(ctxt.GetType().ToString())

    BTW  "Justine" you are a girl a fourteen year old girl learning to program Do you know how cool that is!!!

    Stick with it, girl! Not enough women in the tech fields! Women make 55% of all purchase decisions and 95% of everything is designed for men by men (just ask renee!) A female point of view is in high demand!

    Get back to me with that messagebox. . . and I will show you a neat way to get MDI child forms.

     

     



  • DataTable and MDI form problems in VB.Net 2003