Can someone show me how to hide columns in a VBNet Datagrid.
Say for instance I want to hide the first, third and seventh columns.
Thanks,
Rev. Michael L. Burns
Printable View
Can someone show me how to hide columns in a VBNet Datagrid.
Say for instance I want to hide the first, third and seventh columns.
Thanks,
Rev. Michael L. Burns
If you set datagrid property of AutoGenerateColumns to false you can customize the columns that you want to show. Or if you prefer you can remove columns of a datatable before binding the datatable to the datagrid.
weijian,
Thank you for your quick reply. However, I must be overlooking something because I don't see a property called AutoGenerateColumns.
Pastor Mike
Erm... do you mean you didn't see the property and you just found out or you still don't see the property?
weijian,
When I click on the DataGrid and then look at the properties for the Grid I do no see AutoGenerateColumns as an option.
Pastor Mike
P.S. Here is what I am wanting to do. I have a rsAccountMaster which consists of 20 fields of information that is displayed on my form in textboxes. I also have a grid on the form attached to rsAccountMaster. I want the textboxes to display the contents of the record selected in the grid. However, I only want the grid to display basic information such as the Account, FirstName, LastName, City, State, Country and Zip but I can't seem to hide the extra fields(columns).
maybe I am wrong, but you may need the <asp:repeater> control to have a more flexible custom table...I cant be 100% sure as of yet..
Cander,
Thanks for your response. VBNet seems very powerful but there seems to be a steep learning curve. Things like moving to the next or previous record in vb6 were easy. I haven't been able to even get this to work yet.
Operator head space I'm sure.
Thanks again.
Pastor Mike
Rev,
whoops! I think I mixed up ASP.NET with VB.NET. But anyway, if the datagrid in VB.NET will generate columns automatically, you should then remove the column before biding the data to the datagrid. Why would you need extra columns when you don't need them anyway? :)
Cander,
the repeater control in ASP.NET is pretty flexible and straight forward, but for complex tasks like paging (and sorting?) Datagrid is the only way to go. Repeater only displays all information at once. I used to make my own program to page and bind it to the repeater... until I found out that Datagrid control is just as flexible as Repeater.
weijian,
Yes, I am using vbnet here. The reason that I did not remove the columns before binding is that both the textboxes and the grid are bound to the same place, rsAccountMaster. Sort of like a Master/Detail where the record clicked on in the grid is reflected in the textboxes below. I did this often in vb6 and the just hid the columns when the form loaded.
Appears as one might expect, with additional bells, whistels and power comes increased complexity. ven something as simple as moving through the database now seems complicated.
Makes me glad I don't have an immediate need for it. All my applications for my church are in vb6 and I don't have a pressing need to upgade them. Just trying to stay on the cutting edge of technology. Never know when it might come in handy.
Thanks again for your hel.
Pastor Mike
weijian
sorry, this is no answer to the question, but i would also like to do the same thing.
one of my keys must also be in the datagrid because when i update my dataset when a user entered something in the grid, it complains about my key not containing anything.
therefore i would like to put my key in the datagrid and just hide the column
unless there is another way to do this?
thanks
OK, got this to work.
in my dataset, i set my key's default value like this:
Dim colTaskID As DataColumn
colTaskID = dsMeasures.Tables("Task_Measures").Columns("Task_ID")
colTaskID.DefaultValue = 4
and then i just don't include this field when i build my datagrid with the DataGridColumnStyle() property.
and it will then update automatically when my user enters a new item in my grid! whoohoo!