Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to create header using MSHFlexgrid and add data from textboxes to MSHFlexgrid
Posted
Comments
Sergey Alexandrovich Kryukov 11-Feb-12 16:10pm    
Wow! Does anybody develop in VB6 and why? :-)
--SA

You have to write separate routine To Assign Column Headers For msFlexGrid. Do not insert the textbox data in this routine. if you do so then this will definitely give an error to you
VB
MSFlexGrid.Clear
MSFlexGrid.Rows = 1
MSFlexGrid.TextMatrix(0, 1) = "Header1"
MSFlexGrid.TextMatrix(0, 2) = "Header2"
MSFlexGrid.TextMatrix(0, 3) = "Header3"
MSFlexGrid.TextMatrix(0, 4) = "Header4"
MSFlexGrid.TextMatrix(0, 5) = "Header5"
MSFlexGrid.TextMatrix(0, 6) = "Header6"
MSFlexGrid.TextMatrix(0, 7) = "Header7"

And Then do the following in another routine/function
VB
MSFlexGrid.TextMatrix(0, 1) = Trim(txtText1.Text)
MSFlexGrid.TextMatrix(0, 2) = Trim(txtText2.Text)
MSFlexGrid.TextMatrix(0, 3) = Trim(txtText3.Text)
MSFlexGrid.TextMatrix(0, 4) = Trim(txtText4.Text)
MSFlexGrid.TextMatrix(0, 5) = Trim(txtText5.Text)
MSFlexGrid.TextMatrix(0, 6) = Trim(txtText6.Text)
MSFlexGrid.TextMatrix(0, 7) = Trim(txtText7.Text)
 
Share this answer
 
Comments
Bhags1992 12-Feb-12 5:04am    
thanks
but if i want to add 2nd record then what will i do?
Aniket Yadav 12-Feb-12 5:10am    
increment the row by 1
i.e.
MSFlexGrid.Rows = 1

After inserting the textbox data
Bhags1992 12-Feb-12 5:23am    
im getting that record on same means the 1st record is replace by 2nd
Aniket Yadav 12-Feb-12 5:40am    
Try this
MSFlexGrid.Rows = MSFlexGrid.Rows + 1
Bhags1992 12-Feb-12 5:45am    
MSHFlexGrid1.TextMatrix(1, 1) = Trim(cboAccId.Text)
MSHFlexGrid1.TextMatrix(1, 2) = Trim(cboAccName.Text)
MSHFlexGrid1.TextMatrix(1, 3) = Trim(txtCost.Text)
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1

im using this code
I would suggest you to go through it

http://visualbasic.ittoolbox.com/groups/technical-functional/visualbasic-l/code-of-vb-mshflexgrid-712059[^]

accept n vote if helps otherwise report your queries
--
rahul d.
 
Share this answer
 
To Assign Column Headers For msFlexGrid
VB
MSFlexGrid.Clear
MSFlexGrid.Rows = 2
MSFlexGrid.TextMatrix(0, 1) = "Header1"
MSFlexGrid.TextMatrix(0, 2) = "Header2"
MSFlexGrid.TextMatrix(0, 3) = "Header3"
MSFlexGrid.TextMatrix(0, 4) = "Header4"
MSFlexGrid.TextMatrix(0, 5) = "Header5"
MSFlexGrid.TextMatrix(0, 6) = "Header6"
MSFlexGrid.TextMatrix(0, 7) = "Header7"

After assigning headers to the msFlexGrid Add the data from the textbox as shown below
VB
MSFlexGrid.TextMatrix(0, 1) = Trim(txtText1.Text)
MSFlexGrid.TextMatrix(0, 2) = Trim(txtText2.Text)
MSFlexGrid.TextMatrix(0, 3) = Trim(txtText3.Text)
MSFlexGrid.TextMatrix(0, 4) = Trim(txtText4.Text)
MSFlexGrid.TextMatrix(0, 5) = Trim(txtText5.Text)
MSFlexGrid.TextMatrix(0, 6) = Trim(txtText6.Text)
MSFlexGrid.TextMatrix(0, 7) = Trim(txtText7.Text)

Hope It Will Help You.
Feel Free To Ask If Any Further Queries
 
Share this answer
 
Comments
Bhags1992 12-Feb-12 3:22am    
MSHFlexGrid1.Clear
MSHFlexGrid1.Rows = 2
MSHFlexGrid1.TextMatrix(0, 1) = "Acc_id "
MSHFlexGrid1.TextMatrix(0, 2) = "Acc_name"
MSHFlexGrid1.TextMatrix(0, 3) = "Cost(perunit)"

MSHFlexGrid1.TextMatrix(0, 1) = Trim(cboAccId.Text)
MSHFlexGrid1.TextMatrix(0, 2) = Trim(cboAccName.Text)
MSHFlexGrid1.TextMatrix(0, 3) = Trim(txtCost.Text)

im using this code but it gives subscript out of range error
Aniket Yadav 12-Feb-12 4:11am    
MSHFlexGrid1.Clear
MSHFlexGrid1.Rows = 1 ''Add Just 1 New Row And Try
MSHFlexGrid1.TextMatrix(0, 1) = "Acc_id "
MSHFlexGrid1.TextMatrix(0, 2) = "Acc_name"
MSHFlexGrid1.TextMatrix(0, 3) = "Cost(perunit)"

MSHFlexGrid1.TextMatrix(0, 1) = Trim(cboAccId.Text)
MSHFlexGrid1.TextMatrix(0, 2) = Trim(cboAccName.Text)
MSHFlexGrid1.TextMatrix(0, 3) = Trim(txtCost.Text)
When you add new record, you must increment the row counter also.

Now for eg.
if I have a counter named count then, my code would be,
VB
MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
count = MSHFlexGrid1.Rows
MSHFlexGrid1.TextMatrix(count, 1) = Trim(cboAccId.Text)
MSHFlexGrid1.TextMatrix(count, 2) = Trim(cboAccName.Text)
MSHFlexGrid1.TextMatrix(count, 3) = Trim(txtCost.Text)


This Will Definitely Help You. Please Check
 
Share this answer
 
Comments
Bhags1992 12-Feb-12 6:44am    
it giving subscript out of range error
Aniket Yadav 12-Feb-12 6:46am    
Does your column starts from 0? If yes then
MSHFlexGrid1.TextMatrix(count, 0) = Trim(cboAccId.Text)
MSHFlexGrid1.TextMatrix(count, 1) = Trim(cboAccName.Text)
MSHFlexGrid1.TextMatrix(count, 2) = Trim(txtCost.Text)
Bhags1992 12-Feb-12 6:51am    
still it giving same error
Aniket Yadav 12-Feb-12 6:58am    
will you post the whole routine so that i can check it? Bcoz i have checked the same thing on my side and its working fine. After checking that only i have posted the code on your side.
Bhags1992 12-Feb-12 7:02am    
Private Sub cmdCal_Click()

MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
c = MSHFlexGrid1.Rows

MSHFlexGrid1.TextMatrix(c, 0) = Trim(cboAccId.Text)
MSHFlexGrid1.TextMatrix(c, 1) = Trim(cboAccName.Text)
MSHFlexGrid1.TextMatrix(c, 2) = Trim(txtCost.Text)
End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900