Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding database table to a datagrid or listbox

Status
Not open for further replies.

newora

Programmer
Aug 19, 2003
133
GB
Hi There,

Could someone please give me some pointers as to the best way to achieve the following – I am not really sure whether to use a databound listbox or a datagrid:-

I have a database table that has a column in it which indicates whether the row/record should be included in some statistics that are generated at the end of every month. If the contents of this column are -1 then the row is included in the end of month statistics other it will be 0 and the row will not be included in the month end statistics.

What I wish to do is to allow a user (who will have a certain security permissions when logging into the system) to be able to change which rows/records are included in the month end statistics.

My initial thought was to place the table into a datagrid, but I would like to have a column that basically says “include in month end statistics” and that column will either say yes or no, depending on whether the appropriate column is -1 or 0 respectively – then clicking in the column would allow me to toggle between ayes or no, ideally in a sort of drop down. From what I can see this is not possible with the datragrid control that comes as part of VB 6, but my knowledge of it is quite limited to be honest.

Does anyone know if there is a grid control component out there that might allow me to do something like this (I have looked at component one and can not see anything obvious).

My only other thought at this stage was to place the rows into a databound list box and then allow the appropriate column to be changed by double clicking on the appropriate row ion the listbox.

Any idea / pointers would be much appreciated – thank you.

Newora
 
Thanks for that - I have had a further review of the website and I found the Teue grid pro but it is quite expensive,as it seems you have to either buy all controls or at least 4 licences.

Anyone know of something that would suit someone who has just started up and is strapped for cash!!

Thanks.
 

If you just want to display your data in a grid (and you do not want to edit the data), you can use simple MSFlexGrid (or MSHFlexGrid), or any Grid for that metter, with 2 options on the top of the grid (placed on the Form itself):

o include in month end statistics
o do NOT include in month end statistics

and depending on the option choice of the user, either hide or display the row in question, or re-populate the grid based on the option chosen.

Would that work for you?


Have fun.

---- Andy
 
I generally avoid direct editing of data grids like the plague, by the way. Maybe I'm just overly conservative, but I prefer to have the user select an edit button and pop up the record on another form.
 
Hi Again,

Thank you for the replies - I think that I should now be able to make a start and sxee what I have.

Thanks Again.
 
>... and that column will either say yes or no, depending on whether the appropriate column is -1 or 0 respectively – then clicking in the column would allow me to toggle between ayes or no, ideally in a sort of drop down. From what I can see this is not possible with the datragrid control that comes as part of VB 6 ...

Sure it is possible.

After the Grid loads, set the Column's "Button" property to "True":

DataGrid1.Columns(0).Button = True
DataGrid1.Columns(0).NumberFormat = "yes/no"

Then in the Grid's ButtonClick event set the new Value opposite to the previous value:

Private Sub DataGrid1_ButtonClick(ByVal ColIndex As Integer)
With DataGrid1.Columns(ColIndex)
Select Case ColIndex
Case 0
.Value = (Not .Value)
End Select
End With
End Sub
 
Thanks for the suggestions guys, I will do a bit of 'playing' and see how it looks.

Thanks Again.
 
I generally avoid data binding too, for that matter, with the exception of the data grid. I prefer to do it by hand.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top