Page 1 of 3 123 LastLast
Results 1 to 40 of 100

Thread: MS FlexGrid edit..

  1. #1

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    MS FlexGrid edit..

    ok, so.. if i right click on a card it brings up an editor to show.. in there i can set the card to owned and other things later.. so atm, it works for the first set in generation 1.. but when i try to say i own a card in the second set, i get this error:

    Field 'Table1.Type 2' cannot be a zero-length string.


    Code:
    Private Sub Command5_Click()
        
        Set cmd = New ADODB.Command
        Set cmd.ActiveConnection = cnn
        cmd.CommandText = "update Table1 set [type 2] = '" & cboType2.Text & "', PSA = '" _
                          & cboPSA.Text & "', own = '" & cboOwn.Text & "' where cardset = '" & gCardSet & "' and cardnumber = '" & gCardNumber & "'"
     Set rs = cmd.Execute
        Sleep 2000
        Form2.ResetGrid
    
        Unload Me
    End Sub

    ok.. so i'm confused.. i can say i own a card or not in the first set, but i can't do so in another set? that makes no sense..
    Last edited by elRuffsta; May 7th, 2024 at 02:53 PM.

  2. #2
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,646

    Re: MS FlexGrid edit

    OK, I'm not sure of the problem.

    Are you trying to save a non-zero-length string and it thinks it's zero-length or are you trying to save a zero-length string and the field doesn't allow that?

  3. #3

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: MS FlexGrid edit

    it's a simple "Yes" or "No" in the database.. it works just fine for the first set but not any other set.. you choose yes or no via a combobox in the edit form.. not much to it honestly. just not seeing how it works for the very first set but not any other set i select. that's the issue. why does it only work for the first set but not all sets? that's my question.

  4. #4
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,646

    Re: MS FlexGrid edit

    Well... No = False = 0 and True is anything else which I don't like. I'd like it a lot more if True were one specific value but that's beside the point.

    If it's a boolean field then it should accept any numeric value. If you mean literally "Yes" or "No" then if you're sending it one of those then I'm not sure why it wouldn't accept it because it's either two or three characters.

    I'd have to see the field definition in the table to diagnose it better.

    Edit: I take back the part about a Boolean field accepting any numeric value. I never tried to put anything else in a Boolean field and don't know if it will work or not but it would be simple to intercept and force it to be true or false.

    E.g.

    If Value <> 0 Then

    RecordSet.Field("BooleanField") = True

    Else

    RecordSet.Field("BooleanField") = False

    End if

    Something like that.
    Last edited by cafeenman; Apr 4th, 2024 at 05:17 PM.

  5. #5
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,646

    Re: MS FlexGrid edit

    OK, try this and post the output:

    Code:
    Dim s As String
    
    s = "update Table1 set [type 2] = '" & cboType2.Text & "', PSA = '" & cbopsa.Text & "', own = '" & cboOwn.Text & "' where cardset = '" & gCardSet & "' and cardnumber = '" & gCardNumber & "'"
    
        Set cmd = New ADODB.Command
        Set cmd.ActiveConnection = cnn
        cmd.CommandText = "update Table1 set [type 2] = '" & cboType2.Text & "', PSA = '" _
                          & cbopsa.Text & "', own = '" & cboOwn.Text & "' where cardset = '" & gCardSet & "' and cardnumber = '" & gCardNumber & "'"
     Set rs = cmd.Execute
        Sleep 2000
        Form2.ResetGrid
    
        Unload Me
        
    Debug.Print "cbottype2.Text = " & cbottype2.Text
    Debug.Print "cbopsa.Text = " & cbopsa.Text
    Debug.Print "cboOwn.Text = " & cboOwn.Text
    Debug.Print "gCardSet = " & gCardSet ' I'm not sure what this is or if it's printable.
    Debug.Print "gCardNumber = " & gCardNumber
    Debug.Print "s = " & s

  6. #6

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: MS FlexGrid edit

    atm, i am using a smaller version of the DB than it's upscaled version which i want to use that has lots more in it.. but when i try to do it, i come across alot of issues.. so, i'm stuck between a rock and a hard place.. i'm working on it tho..

    i'm on vacation as of today and going back home for the week.. so i can't put much more time into this until next sunday the 14th... not looking forward to the 18hr drive each way. anyways, we can cotinue on this then.. if i have a chance to pop in on a pc while on vaca i'll check in.. thank you.

  7. #7
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,646

    Re: [ON PAUSE] - MS FlexGrid edit.. i'm going on vacation

    Also too, what's the Sleep command about? Is that just giving the server time to update or something?

  8. #8

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: MS FlexGrid edit

    Quote Originally Posted by cafeenman View Post
    OK, try this and post the output:

    Code:
    Dim s As String
    
    s = "update Table1 set [type 2] = '" & cboType2.Text & "', PSA = '" & cbopsa.Text & "', own = '" & cboOwn.Text & "' where cardset = '" & gCardSet & "' and cardnumber = '" & gCardNumber & "'"
    
        Set cmd = New ADODB.Command
        Set cmd.ActiveConnection = cnn
        cmd.CommandText = "update Table1 set [type 2] = '" & cboType2.Text & "', PSA = '" _
                          & cbopsa.Text & "', own = '" & cboOwn.Text & "' where cardset = '" & gCardSet & "' and cardnumber = '" & gCardNumber & "'"
     Set rs = cmd.Execute
        Sleep 2000
        Form2.ResetGrid
    
        Unload Me
        
    Debug.Print "cbottype2.Text = " & cbottype2.Text
    Debug.Print "cbopsa.Text = " & cbopsa.Text
    Debug.Print "cboOwn.Text = " & cboOwn.Text
    Debug.Print "gCardSet = " & gCardSet ' I'm not sure what this is or if it's printable.
    Debug.Print "gCardNumber = " & gCardNumber
    Debug.Print "s = " & s
    i'll try it out before i go to sleep and respond.. ty, i appreciate it

  9. #9

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit.. i'm going on vacation

    Quote Originally Posted by cafeenman View Post
    Also too, what's the Sleep command about? Is that just giving the server time to update or something?
    i didn't impliment that back in 2004.. all i can tell you is when the change of owning or not owning it takes a second or 2 to update the db and refresh the grid.. personally i expected any changes to be INSTANT and fast.. so i may have to re-do all this

  10. #10
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,646

    Re: [ON PAUSE] - MS FlexGrid edit.. i'm going on vacation

    I'm not sure what happens if you have code after Unload. You might have to move the unload to after all the debug.print stuff. I think it's ok as is but not sure.

    If you get no immediate window output at all that's probably the problem. Or it might stop the form from unloading or who knows what. Someone knows. I'm not one of those people.

  11. #11

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: MS FlexGrid edit

    same error..

  12. #12

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit.. i'm going on vacation

    k time for a shower, sleep and drive 18hrs.. i'll get back to this.. but ty

  13. #13

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit.. i'm going on vacation

    topic on pause.. i cannot keep up with this for a couple of days.. driving and all that.. i'll check back in soon

  14. #14
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,646

    Re: [ON PAUSE] - MS FlexGrid edit.. i'm going on vacation

    Well.... that's all I've got. It's been forever since I played with ADO. I'm assuming your string is correct and not the problem. But someone who knows more about it will have to chime in. Again, I'd like to see the field definition(s) for the fields you're trying to update.

    Enjoy your vacation. I hope you have a great time!

  15. #15

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit.. i'm going on vacation

    back from vacation.. still on pause tho cause i just got back and get back into routine for work and such..

  16. #16
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,157

    Re: [ON PAUSE] - MS FlexGrid edit..

    I don't know how sleep works in VB6, but I would expect that it's the same across all languages in Windows. If that's the case, the sleep statement may not be doing what you are expecting. It will stop all actions in the program for the duration of the sleep. If the database engine is doing something, it may keep on going, but the grid won't be doing any updating during that time.
    My usual boring signature: Nothing

  17. #17

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit..

    "sleep" was just something i was playing with back in 2004.. like i said i want to re-do / refresh this app as i now have reason to do so.. it's just been a LONG LONG time since i've touched this so.. in order for me to to give the example, i would have to makeup a new db without all the full info in it.. i'll get to that.. just need a couple of days as i just got back from vaca.. to be honest, i dunno why i even tried palying with "sleep".. but it was a long time ago so.. i just know atm, it works.. well, semi.. give me a few days and i'll post up the example.

    ty

  18. #18
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,646

    Re: [ON PAUSE] - MS FlexGrid edit..

    I don't like how sleep works so I use this instead:


    Code:
    ' Module Declarations
    
    Public Declare Function GetTickCount Lib "kernel32" () As Long
    
    
    
    Public Sub Sleep(ByRef msInterval As Long)
    Dim nStart As Long
    
    nStart = GetTickCount
    
    Do While GetTickCount - msInterval < nStart
    
      DoEvents
    
    Loop
    
    End Sub

  19. #19
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,157

    Re: [ON PAUSE] - MS FlexGrid edit..

    Don't do that. What you have there is a spin wait, or busy wait. It causes the CPU to run flat out while doing nothing. A few years back, I ran a test where I compared the power consumption on a computer running a spin wait versus one that was just waiting. That thread is in the General Developer forum if you're interested. Basically, I could see a significant increase in power usage while the spin wait was operating, even with a pretty coarse measurement device. Spin waits will boost power usage, boost heat output from the computer, and have a few other negative impacts, all for nothing much.

    However, if you want to do something like that, you can significantly boost the performance of the spin wait by adding some sleep statement in the loop. Sleeping for just 10ms every time through the loop will greatly reduce the strain on the CPU. Still not the best way to wait, but much better than a naked spin wait.
    My usual boring signature: Nothing

  20. #20

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit..

    question..

    so, i have this:
    Code:
    Set cmd = New ADODB.Command
        Set cmd.ActiveConnection = cnn
      cmd.CommandText = "select * from Table1 where cardset = '" & gCardSet & "' order by cardnumber*1"
    'Can I have more than 1 of the above to call info from ANOTHER table in the DB????
        Set rs = cmd.Execute
        Dim i As Integer
        Do While Not rs.EOF
            i = i + 1
            Grid1.Rows = i + 1
            Grid1.RowHeight(i) = 500
            Grid1.TextMatrix(i, 1) = rs!cardnumber
            Grid1.TextMatrix(i, 2) = rs!Name
            
            If Not IsNull(rs![Type 2]) Then
                Grid1.TextMatrix(i, 4) = rs![Type 2]
            End If
            Grid1.TextMatrix(i, 5) = rs!rarity
            Grid1.TextMatrix(i, 7) = "$" & rs!Value
            Grid1.TextMatrix(i, 8) = rs!own
            Grid1.TextMatrix(i, 9) = rs![type 1]
            Grid1.TextMatrix(i, 10) = rs!PSA
            Grid1.TextMatrix(i, 11) = rs!notes 'Hidden
            rs.MoveNext
        Loop
        Label3(0).Caption = CStr(rs.RecordCount) 'This gives the amt of cards in the set
    'So, could i have Label3(1).caption to give the release date of the set from another table?
    basically asked my question within the code.. so, ok.. i'm getting info i want in the MS FlexGrid and record count of said set.. however, i have another table that holds more info per generation and sets.. like what year a set was released.. sooo basically what i'm asking for is how do i call info from 2 different tables? my other table has a field called "Released" and in that column there are release dates for each set... ty
    Last edited by elRuffsta; Apr 15th, 2024 at 01:24 PM.

  21. #21
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,157

    Re: [ON PAUSE] - MS FlexGrid edit..

    Generally, that's done by joining the two tables, assuming you have fields that can join the table. You'd want to get away from *, if you do that, though * would still work after a fashion. The SQL would look something like this:

    SELECT Table1.Field1, Table2.Field1, Table1.Field2...etc.
    FROM Table1 INNER JOIN Table2 ON Table1.FieldX = Table2.FieldY

    Joins can get quite complicated, especially when you join many different tables together. You also have LEFT JOINs (get any record from the left hand table and only matching records from the right hand table), RIGHT JOINs (the opposite of Left join, and fairly rare), and a few others. By far, the most common are the INNER and LEFT joins.

    Beyond that, it comes down to the actual tables, how they relate, and what fields you want.
    My usual boring signature: Nothing

  22. #22
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,646

    Re: [ON PAUSE] - MS FlexGrid edit..

    Quote Originally Posted by Shaggy Hiker View Post
    Don't do that. What you have there is a spin wait, or busy wait. It causes the CPU to run flat out while doing nothing. A few years back, I ran a test where I compared the power consumption on a computer running a spin wait versus one that was just waiting. That thread is in the General Developer forum if you're interested. Basically, I could see a significant increase in power usage while the spin wait was operating, even with a pretty coarse measurement device. Spin waits will boost power usage, boost heat output from the computer, and have a few other negative impacts, all for nothing much.

    However, if you want to do something like that, you can significantly boost the performance of the spin wait by adding some sleep statement in the loop. Sleeping for just 10ms every time through the loop will greatly reduce the strain on the CPU. Still not the best way to wait, but much better than a naked spin wait.

    Then I misunderstood how it works. I thought Doevents was giving control back to the system so it could do other things.

  23. #23

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit..

    Quote Originally Posted by Shaggy Hiker View Post
    Generally, that's done by joining the two tables, assuming you have fields that can join the table. You'd want to get away from *, if you do that, though * would still work after a fashion. The SQL would look something like this:

    SELECT Table1.Field1, Table2.Field1, Table1.Field2...etc.
    FROM Table1 INNER JOIN Table2 ON Table1.FieldX = Table2.FieldY

    Joins can get quite complicated, especially when you join many different tables together. You also have LEFT JOINs (get any record from the left hand table and only matching records from the right hand table), RIGHT JOINs (the opposite of Left join, and fairly rare), and a few others. By far, the most common are the INNER and LEFT joins.

    Beyond that, it comes down to the actual tables, how they relate, and what fields you want.
    seems complicated.. i just want to pull the RELEASE date on the set that is showing in the flexgrid from table 2 into label3(1).caption.. table 2 doesn't have anything else i really want to grab from it.. it's more a simple set info table.. release date, which generation the set belongs to and a couple of other things.. i just want the release date from table 2.


    something like: in table 2 there is generation, cardset, Released, etc.. so whatever set is being displayed in the flexgrid the date will show in a label for that specific set
    Code:
    cmd.CommandText = "select * from Table2 where cardset = '" & gCardSet & "' Released"
    'Now show that date in Label3(1).caption
    * i changed "Set" to "CardSet" in the DB to match coding.. but not shown in picture as i didn't want to redo the image..
    Attached Images Attached Images  
    Last edited by elRuffsta; Apr 15th, 2024 at 04:13 PM.

  24. #24

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit..

    what about just adding a NEW cmd? at the end of the current code???

    Set cmd = New ADODB.Command
    Set cmd.ActiveConnection = cnn
    cmd.CommandText = "select * from Table2 where cardset = '" & gCardSet & "'Released"
    'Can I have more than 1 of the above to call info from ANOTHER table in the DB????
    Set rs = cmd.Execute


    and so on?



    *OR what about a private function and call the function at the end? just thinking out loud lol..
    Last edited by elRuffsta; Apr 15th, 2024 at 08:32 PM.

  25. #25

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit..

    like..

    Code:
    Private Function ReleaseDate()
        Set cmd = New ADODB.Command
        Set cmd.ActiveConnection = cnn
      cmd.CommandText = "select * from Table2 where cardset = '" & gCardSet & "' Released"
        Set rs = cmd.Execute
        
        
        
        yada yada yada
    
    form2.label3(1).caption = DATE OF SET
    End Function
    i dunno.. just throwing it out there... this way i'm not joining tables and all that..

  26. #26
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,004

    Re: [ON PAUSE] - MS FlexGrid edit..

    If both tables contain the same IDs then in theory you can do 2 queries and then fill the first column of the grid with the content of the first query and when finished fill column 2 with the content of the second query.
    But when the IDs are the same then it should be possible to retrieve the data with a single query with a join query
    https://www.w3schools.com/sql/sql_join_left.asp
    Code:
    SELECT column_name(s)
    FROM table1
    LEFT JOIN table2
    ON table1.column_name = table2.column_name;

  27. #27

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit..

    If both tables contain the same IDs
    they don't...

  28. #28
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,004

    Re: [ON PAUSE] - MS FlexGrid edit..

    Then I don’t understand what you want to and have the information in the columns of each row are related to each other

  29. #29
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,157

    Re: [ON PAUSE] - MS FlexGrid edit..

    Quote Originally Posted by cafeenman View Post
    Then I misunderstood how it works. I thought Doevents was giving control back to the system so it could do other things.
    Yes, mostly. Do Events pauses the currently executing code and lets the system pump any messages that are queued up. There may be some paints, timer ticks, and whatnot, waiting to be dealt with. Normally, those are all work, so the CPU doesn't rest during that time. Also, there often won't be any messages, so the program is essentially saying:

    Are there any messages? No, ok, on we go...Are there any messages? No, ok, on we go...etc. It'll be ripping through that so fast that it won't slow down. If you watch the performance monitor, you might see one CPU core pegged for the duration. Back when we only had a single core, then the whole computer would be pegged. That's not quite the opposite to doing nothing. It's like the difference between sitting in a chair and running on a treadmill: In both cases, you won't get anywhere, but one takes a lot more effort.
    My usual boring signature: Nothing

  30. #30

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit..

    k.. so, what i have on my desktop is 2 projects.. well.. both are 1 project.. i'm trying to combine them both into 1 as each is a different section of the same project.. what works with 1 db the other doesn't - each one has a similar DB but one is more enhanced.. so the ms flexgrid is messing up but works well with the simpiler version of the DB where i want it to work with the full enhanced DB.. so.. i guess i am gonna have re-do this whole thing from scratch.. not that i want to cause each side works but not with each other. keep in mind, i ORIGINALLY started this way back in 2004 and i have made adjustments since and most recently.

    i'll get back to posting when i'm done re-designing / putting this altogether as 1 project as it suppossed to be... shaggy has suggested to me in making a demo to share publically with some simple tables and such without giving away my full DB and all - (as he is the only one i told what my project is / about), so that is what i'm gonna do.. ty for your patience.
    Last edited by elRuffsta; Apr 17th, 2024 at 08:18 PM.

  31. #31

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit..

    i only want certain things centered.. basically just 1 thing NOT centered.. how do i do this for each item below? so just the NAMES themselves are NOT centered... ty in advance


    Code:
    Option Explicit
    Private Sub Form_Load()
    
        'Setup the grid..
        Grid1.ColWidth(0) = 600 'X & CHECKMARK image.....i want it centered
        Grid1.ColWidth(1) = 400 'card number..........i want it centered
        Grid1.ColWidth(2) = 2200 'card name.......................................i DON'T want the names centered - RED
        Grid1.ColWidth(3) = 800 'Gender..................i want it centered
        Grid1.ColWidth(4) = 800 'Type 1..................i want it centered
        Grid1.ColWidth(5) = 800 'Type 2..................i want it centered
        Grid1.ColWidth(6) = 2000 'Other..................i want it centered
        Grid1.ColWidth(7) = 800 'rarity....................i want it centered
        Grid1.ColWidth(8) = 800 'PSA.................... i want it centered
        Grid1.ColWidth(9) = 1000 'value..................i want it centered
    
        'i want all the column headers centered
        Grid1.TextMatrix(0, 0) = "Own"
        Grid1.TextMatrix(0, 1) = "#"
        Grid1.TextMatrix(0, 2) = "Name"
        Grid1.TextMatrix(0, 3) = "Gender"
        Grid1.TextMatrix(0, 4) = "Type 1"
        Grid1.TextMatrix(0, 5) = "Type 2"
        Grid1.TextMatrix(0, 6) = "Other"
        Grid1.TextMatrix(0, 7) = "Rarity"
        Grid1.TextMatrix(0, 8) = "PSA"
        Grid1.TextMatrix(0, 9) = "Value"
           
    End Sub
    Attached Images Attached Images  
    Last edited by elRuffsta; Apr 29th, 2024 at 03:08 PM.

  32. #32
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,004

    Re: [ON PAUSE] - MS FlexGrid edit..

    I’m sure I posted the same link in one of your other threads, but here it is again:
    https://www.vbforums.com/showthread....Style-property

  33. #33

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit..

    umm.. that's a FILL COLOR thread and such... that has nothing to do with specific aliging headers and specific fields that i am looking for.. please revisit my above code and picture.. each line should have a code to do what i want it to do.. or a block of code for those specific items. i'm not worried about colors.. i just colored it so it can be seen as what i want centered and what i don't want centered.
    Last edited by elRuffsta; Apr 29th, 2024 at 03:49 PM.

  34. #34
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,004

    Re: [ON PAUSE] - MS FlexGrid edit..

    Check the sample.
    It’s about most cell properties
    Code:
    FG_Cell MSFlexGrid1, fgcsAllignment, 2, 4, 3, 4, flexAlignRightCenter

  35. #35

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit..

    it doesn't work for me even changing it to fit the code.. so either i am missing something OR it just doesn't work.. but ty anyways.

  36. #36
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,004

    Re: [ON PAUSE] - MS FlexGrid edit..

    Have you tried the sample in a new project and did this work for you?
    If it did then something in your project is conflicting with your own code and/or properties

  37. #37

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit..

    my entire code for that form atm.. so "how" is it conflicting? and yes, i did try it... again, ty.. but what you suggested ISN'T working for me.. again, each line has to have a specific code or a block of code to accomplish what i am trying to do.. i'm not here to debate.. but my code is clear as it sits... but ty anyways


    Code:
    Option Explicit
    Private Sub Form_Load()
    
        'Setup the grid..
        Grid1.ColWidth(0) = 600 'X & CHECKMARK image.....i want it centered
        Grid1.ColWidth(1) = 400 'card number.............i want it centered
        Grid1.ColWidth(2) = 2200 'card name.......................................i DON'T want the names centered
        Grid1.ColWidth(3) = 800 'Gender image..................i want it centered
        Grid1.ColWidth(4) = 800 'Type 1 image..................i want it centered
        Grid1.ColWidth(5) = 800 'Type 2 image..................i want it centered
        Grid1.ColWidth(6) = 2000 'Other image...................i want it centered
        Grid1.ColWidth(7) = 800 'rarity image.................i want it centered
        Grid1.ColWidth(8) = 800 'PSA image.................... i want it centered
        Grid1.ColWidth(9) = 1000 'dollar value..................i want it centered
    
        'i want all the column headers centered
        Grid1.TextMatrix(0, 0) = "Own"
        Grid1.TextMatrix(0, 1) = "#"
        Grid1.TextMatrix(0, 2) = "Name"
        Grid1.TextMatrix(0, 3) = "Gender"
        Grid1.TextMatrix(0, 4) = "Type 1"
        Grid1.TextMatrix(0, 5) = "Type 2"
        Grid1.TextMatrix(0, 6) = "Other"
        Grid1.TextMatrix(0, 7) = "Rarity"
        Grid1.TextMatrix(0, 8) = "PSA"
        Grid1.TextMatrix(0, 9) = "Value"
           
    End Sub
    
    Private Sub mnuExit_Click()
    Unload Me
    End Sub
    
    Private Sub mnuMainMenu_Click()
    Unload Me
    frmMain.Show vbModal
    End Sub
    Last edited by elRuffsta; Apr 30th, 2024 at 03:45 PM.

  38. #38
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,004

    Re: [ON PAUSE] - MS FlexGrid edit..

    It's as clear as it is, but I see no code for aligning the values of the cells.

    I took your code and my sample and merged them and it does work:
    Code:
    Option Explicit
    
    Private Enum FGCellStyle
      fgcsBackColor = 1
      fgcsForeColor = 2
      fgcsText = 3
      fgcsTextStyle = 4
      fgcsFontName = 5
      fgcsFontBold = 6
      fgcsFontItalic = 7
      fgcsAllignment = 8
    End Enum
    
    Private Sub Form_Load()
      Dim lCol As Long, lRow As Long
      
      Grid1.Cols = 10
      Grid1.Rows = 5
      
      'Setup the grid..
      Grid1.ColWidth(0) = 600 'X & CHECKMARK image.....i want it centered
      Grid1.ColWidth(1) = 400 'card number.............i want it centered
      Grid1.ColWidth(2) = 2200 'card name.......................................i DON'T want the names centered
      Grid1.ColWidth(3) = 800 'Gender..................i want it centered
      Grid1.ColWidth(4) = 800 'Type 1..................i want it centered
      Grid1.ColWidth(5) = 800 'Type 2..................i want it centered
      Grid1.ColWidth(6) = 2000 'Other...................i want it centered
      Grid1.ColWidth(7) = 800 'rarity.................i want it centered
      Grid1.ColWidth(8) = 800 'PSA.................... i want it centered
      Grid1.ColWidth(9) = 1000 'value..................i want it centered
    
      'i want all the column headers centered
      Grid1.TextMatrix(0, 0) = "Own"
      Grid1.TextMatrix(0, 1) = "#"
      Grid1.TextMatrix(0, 2) = "Name"
      Grid1.TextMatrix(0, 3) = "Gender"
      Grid1.TextMatrix(0, 4) = "Type 1"
      Grid1.TextMatrix(0, 5) = "Type 2"
      Grid1.TextMatrix(0, 6) = "Other"
      Grid1.TextMatrix(0, 7) = "Rarity"
      Grid1.TextMatrix(0, 8) = "PSA"
      Grid1.TextMatrix(0, 9) = "Value"
        
        
      ' Fill the grid with some bogus data
      With Grid1
        For lCol = 0 To .Cols - 1
          For lRow = 1 To .Rows - 1
            .TextMatrix(lRow, lCol) = "R" & CStr(lRow) & "C" & CStr(lCol)
          Next
          ' All cells centered, expect the cells in column 2
          If lCol = 2 Then
            FG_Cell Grid1, fgcsAllignment, 0, lCol, .Rows - 1, .Cols - 1, flexAlignLeftCenter
          Else
            FG_Cell Grid1, fgcsAllignment, 0, lCol, .Rows - 1, .Cols - 1, flexAlignCenterCenter
          End If
        Next
      End With
           
    End Sub
    
    Private Sub FG_Cell(FG As MSFlexGrid, ByVal What As FGCellStyle, Row1 As Long, Col1 As Long, Row2 As Long, Col2 As Long, Value As Variant)
      Dim PrevRowCol(3) As Long    ' to store the actual settings
      Dim PrevFillStyle As Integer ' to store the actual settings
       
      With FG
        .Redraw = False
        
        ' Store current settings
        PrevFillStyle = .FillStyle
        PrevRowCol(0) = .Row:    PrevRowCol(2) = .RowSel
        PrevRowCol(1) = .Col:    PrevRowCol(3) = .ColSel
        
        ' Set the range
        .FillStyle = flexFillRepeat
        .Row = Row1:    .Col = Col1
        .RowSel = Row2: .ColSel = Col2
        
        ' Apply changes
        Select Case What
          Case fgcsBackColor:    .CellBackColor = Value
          Case fgcsForeColor:    .CellForeColor = Value
          Case fgcsText:         .Text = Value
          Case fgcsTextStyle:    .CellTextStyle = Value
          Case fgcsFontName:     .CellFontName = Value
          Case fgcsFontBold:     .CellFontBold = Value
          Case fgcsFontItalic:   .CellFontItalic = Value
          Case fgcsAllignment:   .CellAlignment = Value
        End Select
        
        ' Restore settings
        .FillStyle = PrevFillStyle
        .Row = PrevRowCol(0):    .Col = PrevRowCol(1)
        .RowSel = PrevRowCol(2): .ColSel = PrevRowCol(3)
        
        .Redraw = True
      End With
    End Sub

  39. #39
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,004

    Re: [ON PAUSE] - MS FlexGrid edit..

    Now with a command button to add a new row instead of filling the grid in the form_load
    Code:
    Option Explicit
    
    Private Enum FGCellStyle
      fgcsBackColor = 1
      fgcsForeColor = 2
      fgcsText = 3
      fgcsTextStyle = 4
      fgcsFontName = 5
      fgcsFontBold = 6
      fgcsFontItalic = 7
      fgcsAllignment = 8
    End Enum
    
    Private Sub Form_Load()
      Dim lCol As Long, lRow As Long
      
      Grid1.Cols = 10
      Grid1.Rows = 1
      
      'Setup the grid..
      Grid1.ColWidth(0) = 600 'X & CHECKMARK image.....i want it centered
      Grid1.ColWidth(1) = 400 'card number.............i want it centered
      Grid1.ColWidth(2) = 2200 'card name.......................................i DON'T want the names centered
      Grid1.ColWidth(3) = 800 'Gender..................i want it centered
      Grid1.ColWidth(4) = 800 'Type 1..................i want it centered
      Grid1.ColWidth(5) = 800 'Type 2..................i want it centered
      Grid1.ColWidth(6) = 2000 'Other...................i want it centered
      Grid1.ColWidth(7) = 800 'rarity.................i want it centered
      Grid1.ColWidth(8) = 800 'PSA.................... i want it centered
      Grid1.ColWidth(9) = 1000 'value..................i want it centered
    
      'i want all the column headers centered
      Grid1.TextMatrix(0, 0) = "Own"
      Grid1.TextMatrix(0, 1) = "#"
      Grid1.TextMatrix(0, 2) = "Name"
      Grid1.TextMatrix(0, 3) = "Gender"
      Grid1.TextMatrix(0, 4) = "Type 1"
      Grid1.TextMatrix(0, 5) = "Type 2"
      Grid1.TextMatrix(0, 6) = "Other"
      Grid1.TextMatrix(0, 7) = "Rarity"
      Grid1.TextMatrix(0, 8) = "PSA"
      Grid1.TextMatrix(0, 9) = "Value"
      
      ' Set the default alignment for the complete columns
      For lCol = 0 To Grid1.Cols - 1
        Select Case lCol
          Case 2:    Grid1.ColAlignment(lCol) = flexAlignLeftCenter
          Case Else: Grid1.ColAlignment(lCol) = flexAlignCenterCenter
        End Select
      Next lCol
      
      ' Overrule the aligment for the headers, the should be centered
      FG_Cell Grid1, fgcsAllignment, 0, 0, 0, Grid1.Cols - 1, flexAlignCenterCenter
    End Sub
    
    Private Sub Command1_Click()
      Dim lRow As Long, lCol As Long
      
      ' Fill the grid with some bogus data
      With Grid1
        lRow = .Rows: .Rows = .Rows + 1
        For lCol = 0 To .Cols - 1
          .TextMatrix(lRow, lCol) = "R" & CStr(lRow) & "C" & CStr(lCol)
        Next
      End With
      
    End Sub
    
    Private Sub FG_Cell(FG As MSFlexGrid, ByVal What As FGCellStyle, Row1 As Long, Col1 As Long, Row2 As Long, Col2 As Long, Value As Variant)
      Dim PrevRowCol(3) As Long    ' to store the actual settings
      Dim PrevFillStyle As Integer ' to store the actual settings
       
      With FG
        .Redraw = False
        
        ' Store current settings
        PrevFillStyle = .FillStyle
        PrevRowCol(0) = .Row:    PrevRowCol(2) = .RowSel
        PrevRowCol(1) = .Col:    PrevRowCol(3) = .ColSel
        
        ' Set the range
        .FillStyle = flexFillRepeat
        .Row = Row1:    .Col = Col1
        .RowSel = Row2: .ColSel = Col2
        
        ' Apply changes
        Select Case What
          Case fgcsBackColor:    .CellBackColor = Value
          Case fgcsForeColor:    .CellForeColor = Value
          Case fgcsText:         .Text = Value
          Case fgcsTextStyle:    .CellTextStyle = Value
          Case fgcsFontName:     .CellFontName = Value
          Case fgcsFontBold:     .CellFontBold = Value
          Case fgcsFontItalic:   .CellFontItalic = Value
          Case fgcsAllignment:   .CellAlignment = Value
        End Select
        
        ' Restore settings
        .FillStyle = PrevFillStyle
        .Row = PrevRowCol(0):    .Col = PrevRowCol(1)
        .RowSel = PrevRowCol(2): .ColSel = PrevRowCol(3)
        
        .Redraw = True
      End With
    End Sub
    Last edited by Arnoutdv; Apr 30th, 2024 at 01:35 AM.

  40. #40

    Thread Starter
    Banned
    Join Date
    May 2014
    Location
    OH
    Posts
    459

    Re: [ON PAUSE] - MS FlexGrid edit..

    ty, i'll try it out in a bit.. i wasn't expecting such a chunk of code.. i thought it would be a lot smaller

    also, i won't be adding anymore rows


    ok, i dunno why it's making rows and filling them... this will be reading from a database so the rows will eventually be made and filled automatically.. also, how do i center the column HEADER for "NAME", but not list the names in the center? or is it that it cannot be done by default the whole column becomes centered? can we stop it from creating the extra 3 rows and filling them - as it will be reading from a DB?


    ahh.. i see why it's making and filling rows.. well filling them, haven't figured out why / how it's adding 3 more rows tho...
    Code:
    ' Fill the grid with some bogus data
    
    .TextMatrix(lRow, lCol) = "R" & CStr(lRow) & "C" & CStr(lCol) 'yeah, this is where it's gonna read from a DB
    Last edited by elRuffsta; Apr 30th, 2024 at 06:13 PM.

Page 1 of 3 123 LastLast

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