Question:
Datagrid in VB.Net?
2007-08-03 11:34:21 UTC
I have a datagrid that retrieves information from the database and below the datagrid there are several other controls. When the datagrid is displayed, sometimes it will be too long that it overlapped the controls below the datagrid, how can I make the controls below the datagrid flexible so when the datagrid is displayed the controls below the datagrid should move below according to the length of the datagrid? I will not know how long the datagrid will be because it is retrieved from the database and sometimes it might be short and sometimes it might be long, so i can't set the controls to a specific place. How can I solve this? I've tried putting the datagrid in a table row and adding the controls to the next row of the table but the datagrid will have error. Thanks, any help will be greatly appreciated!
Six answers:
Einstein
2007-08-03 13:13:35 UTC
In Visual Basic .Net the DataGrid control has events called DataGrid1_Resize() and Location_Changed().



Place code in the DataGrid's Resize() event to cause other controls beneath it to shift their positon anytime the DataGrid's dimensions change.



Hint: You might consider placing the controls that are located beneath the DataGrid into some sort of container, i.e., Panel. In that way you just have to reset the Top property of just one control, versus several.



For Example:



Private Sub Resize()

Dim intTop as Integer

Dim intHeight as Integer



intTop = DataGrid1.Top

intHeight = DataGrid1.Height



'Reset the Top properties of the controls beneath DataGrid1

thisControl1.Top = intTop + intHeight + 25

End Sub
Duncan P
2007-08-03 11:55:42 UTC
I would use the datagridview control rather then the datagrid control. But... if you still want to use the datagrid control, I am pretty sure you can fix the size of it. If not, then another option would be to get the size and coordinates of the datagrid control once rendered and re-locate the other controls based on the location of the datagrid. To re-locate the other controls just take the coordinates of the specific part of the datagrid and add that to the location of the control to be moved. I can't remember the specific properties that you use to do this, but I have done this before with other controls.
2007-08-03 11:41:00 UTC
I have used the datagrid many times and I truly never like it. I use the MSFlexGrid and it seems to respond much better. Plus it has scroll bars for going to the right for extended data. You can also set check boxes, pull downs, etc on the MSFlexgrid to allow for selections and then you can write code to update the rows and fields that have been changed.



Sounds like though for this if your stuck using the datagrid would be to put your controls before the dataset and then see if they stay. Not sure how it looks to really describe some options for you.
Dave
2007-08-03 14:38:24 UTC
If you put the DataGrid in side of a table cell then everything should automatically happen for you.





















...











This should place the button directly below the datagrid regardless of size.



If you want the buttons to be the same place on the screen regardless then you should wrap a div tag around your data grid and give it a specific height attibute in th style attribute. The you can turn overflow to auto on and your table will scroll within the page that is displayed.
?
2016-12-11 14:19:00 UTC
I did this for my database in my internet site All you like is to maintain your datagrid values into CSV values (ASCII document which would be opened in Notpad) and on your MySQL Admin, import that document into you database appreciate my profile, i'm the VBAXLMan
bobby
2007-08-03 11:38:37 UTC
Please use a panel control and place the grid on it. Like keep the other control on another panel below the grid


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...