Results 1 to 3 of 3

Thread: Why cant i do this? (yes another cast question)

  1. #1

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Why cant i do this? (yes another cast question)

    Im sorry to be asking so many cast questions lately im still wraping my head around it ( the vet analogy helped)


    basicly i am trying to

    make a datagridview and insert information from a certian index of invoice binding sources

    from that datagridview i want to select a certian row and index ( get the value of one cell basicly)

    check to see if that string is empty or null
    if so delete that entire line out of invoice binding source


    the problem i am running into is with casting ( again) i want invoicedgv to = the value of invoicebindingsource

    ive been googleing for the last 2 days and realy cant find anything to point me in the right direction

    i assume its one of these possiblitys

    1) the invoicedgv reqires something ilke a .value or .cell and i can add the value directly to that. ( i have yet to find anything by pokeing threw inteli sense

    2) i am casting wrong ( high probablity)

    3) something else




    C#
    Code:
    DataGridView invoicedgv = (DataGridView)invoicebindingsource[index];
    String invoiceCheck =invoicedgv["Name",index].ToString().Trim();
                        if (string.IsNullOrEmpty(invoiceCheck))
                        {
                            invoicebindingsource.RemoveAt(index);
                        }
    vb.net = this works
    VB Code:
    1. If DirectCast(Me.invoicebindingsource(index), DataRowView)("Name").ToString().Trim() = String.Empty Then
    2.                     'The Name field does not contain any non-whitespace characters.
    3.                     Me.invoicebindingsource.RemoveAt(index)
    4.                 End If

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Why cant i do this? (yes another cast question)

    You're trying to cast the item from the BindingSource as a DataGridView, not a DataRowView.

    We all do spastic stuff. I posted in the Database forum the other day about transactions working with SQL Server Express 2005 and not MSDE2000 when I'd simply stopped the Transaction Coordinator service on MSDE. We're all human. Just some of us don't smell like it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member Crash893's Avatar
    Join Date
    Dec 2005
    Posts
    930

    Re: Why cant i do this? (yes another cast question)

    well im getting closer

    also with the datarow view i dont need to put the extra indexing information in there becuase its just one row

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width