Results 1 to 14 of 14

Thread: [RESOLVED] subtracting the highlighted record in msflexgrid

  1. #1

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Resolved [RESOLVED] subtracting the highlighted record in msflexgrid


    I am having trouble subtracting the highlighted record in the msflexgrid
    it seems to be subtracting the record in the listbox instead of the highlighted one in the msflexgrid?
    VB Code:
    1. Private Sub cmdRemoveEntry_Click()
    2.         With Adodc1.Recordset
    3.         .Move (MSHFlexGrid1.Row - 1)
    4.         .Delete
    5.         .Requery
    6.     End With
    7.     Adodc1.Refresh
    8.     Set MSHFlexGrid1.DataSource = Adodc1
    9.     MSHFlexGrid1.FormatString = "Item Name       '|ect....
    10.     txtEstimateTotal.Text = Format(Val(txtEstimateTotal.Text) - rs("TotalAmount"), "##.00")
    11.     txtEstimatePrice.Text = Format(Val(txtEstimatePrice.Text) - rs("ItemPrice"), "##.00")
    12.     txtEstimateTax.Text = Format(Val(txtEstimateTotal.Text) - Val(txtEstimatePrice.Text), "##.00")
    13. 'the problem lies in the - rs(...) part this needs to be changed to the highlighted record in the flexgrid
    14. End Sub
    Last edited by Quizton; Feb 5th, 2006 at 02:38 PM. Reason: still not working quite right

  2. #2

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: subtracting the highlighted record in msflexgrid

    any suggestions would be greatly appreciated

  3. #3
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: subtracting the highlighted record in msflexgrid

    could you explain it in detail, sorry I couldnt understand it
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  4. #4

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: subtracting the highlighted record in msflexgrid

    Format(Val(txtEstimateTotal.Text) - rs("TotalAmount"), "##.00")

    the txtestimatetotal needs to subtract the highlighted total in the grid instead of the rs("totalamount")

    I just dont know how to select the highlighted record in the grid itself?
    thanks for the replies

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: subtracting the highlighted record in msflexgrid

    If only one cell is selected, use: MSHFlexGrid1.Text

    If you want to get the contents of a specific cell, use: MSHFlexGrid1.TextMatrix(RowNumber, ColumnNumber)

  6. #6

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: subtracting the highlighted record in msflexgrid

    is there a way to just select the highlighted record?
    or do you have to choose the row and column?

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: subtracting the highlighted record in msflexgrid

    MSHFlexGrid1.Text returns the text of the current cell, no matter how .Row and .Col have been set (code, or UI).

    To get certain cells from the current row, you can use something like:
    VB Code:
    1. Column1 = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 1)
    2. Column2 = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2)
    which is the same as this:
    VB Code:
    1. With MSHFlexGrid1
    2.   Column1 = .TextMatrix(.Row, 1)
    3.   Column2 = .TextMatrix(.Row, 2)
    4. End With

  8. #8

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: subtracting the highlighted record in msflexgrid

    Ive been trying to get this to work and it seems I cant use it in the math formula ?
    Ill keep trying
    thanks for the replies

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: subtracting the highlighted record in msflexgrid

    Show what code you are trying, and tell us what the problem is.

  10. #10

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: subtracting the highlighted record in msflexgrid

    VB Code:
    1. Private Sub cmdRemoveEntry_Click()
    2.         With Adodc1.Recordset
    3.         .Move (MSHFlexGrid1.Row - 1)
    4.         .Delete
    5.         .Requery
    6.     End With
    7.     Adodc1.Refresh
    8.     Set MSHFlexGrid1.DataSource = Adodc1
    9.     MSHFlexGrid1.FormatString = "Item Name       '|ect....
    10.     txtEstimateTotal.Text = Format(Val(txtEstimateTotal.Text) - rs("TotalAmount"), "##.00")
    11.     txtEstimatePrice.Text = Format(Val(txtEstimatePrice.Text) - rs("ItemPrice"), "##.00")
    12.     txtEstimateTax.Text = Format(Val(txtEstimateTotal.Text) - Val(txtEstimatePrice.Text), "##.00")
    13.  
    14. End Sub
    that is my code to remove a entry also when I focus on a selection in the grid then that is the one that gets deleted I tried changing the -rs("totalamount") to the textmatrix and it didnt seem to work.
    I am trying to subtract the columns with numbers in there from a totalamount (the estimate can range from 1 item thru 100 items)on a estimate instead of using the -rs because if I use the -rs then I will have to click on the record in the listbox above that has the services db or else it will subtract the wrong one sorry for the late replies I am home with a horrible cold
    maybe I should wait and try when Im feelin a bit better.

  11. #11

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: subtracting the highlighted record in msflexgrid

    is there a way to select the format were total amount is in the grid
    because it should subtract it then delete it since it will delete on focus I should be able to subtract on focus as well?

    I thank you for the replies
    I must be overlooking something here or possibly having trouble since I used a adodc data bar on this one wile all my other stuff is connected by code

    I changed the add procedure to add to a rs of a different name than the one in the lisbox stuff and it bugged during the remove procedure saying item not found in this collection?
    probly since it is bound? Ill try to code this and take out the bound controll and see if that cures my issues
    this is the firs time I used a bound control in this project as well as the first time Ive used the flexgrid
    Last edited by Quizton; Feb 7th, 2006 at 01:35 AM.

  12. #12
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: subtracting the highlighted record in msflexgrid

    It is "data control", not "data bar"... and it is evil That could well be the cause of some of your problems. "item not found in this collection" means you have asked for a field that isn't in the recordset.

    To use the grid text in your calculation, you can use this (just change 1 to the column you want to read from):
    VB Code:
    1. txtEstimateTotal.Text = Format(Val(txtEstimateTotal.Text) - Val(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, [B]1[/B])), "##.00")
    ..Note however that this reads from the current row, and I'm not sure what that will be after you have reloaded via the data control; you may want to specify a row instead.

    If you want to subtract the value that is highlighted at the time when the button is clicked, this line should just be moved to the top of the sub - while the value is still there.

  13. #13

    Thread Starter
    Addicted Member Quizton's Avatar
    Join Date
    Dec 2005
    Location
    VB Forums
    Posts
    209

    Re: subtracting the highlighted record in msflexgrid


    hey thanks again SI
    it works perfectly now, I wasnt using VAL is why It didnt work sooner it will work even on reload I had to change the rows to minus 1 of the actual rows in the format but it seems to work well

    And you are right about the evil binding I usualy dont ever do it but thought I could on this part to save some time but have had issues with it


    It seems if I add 2 or more records to the flexgrid it will mess up the highlight and act like its multiselecting even though it is set to false. If I reload the page after Im done adding the records to the grids db then it will highlight how it is supposed to ?

    I am going to try and find me a mshflexgrid tutorial and link this all by code and Im sure it will work properly after that


    thanks again for the help you have helped me learn how to manipulate the grids and it now subtracts well
    Last edited by Quizton; Feb 7th, 2006 at 12:02 PM.

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,930

    Re: [RESOLVED] subtracting the highlighted record in msflexgrid

    I dont know of any tutorials, but there are several threads on the forums which explain how to do various things with it.

    Here's one, which has a sub you can use to fill a grid from a recordset:
    http://www.vbforums.com/showpost.php...9&postcount=16

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