Stats: 3,191,145 members, 7,943,111 topics. Date: Sunday, 08 September 2024 at 06:09 AM |
Nairaland Forum / Science/Technology / Programming / How Do I Edit Datagrid ? (9516 Views)
How To Edit The Source Code Of Joomla Individual Pages / Help On Loading Sql Table Data Into Datagrid Using OOP Approach C# (2) (3) (4)
How Do I Edit Datagrid ? by luckyCO(m): 5:10pm On Feb 05, 2007 |
How can I increase Datagrid row and column without binding it to a database. Again how can I bind Textbox control to datagrid such that I can Type in Datagrid cell using VB.Net |
Re: How Do I Edit Datagrid ? by rookie(m): 8:19pm On Feb 05, 2007 |
Below is a breif guide on how you can bind a textbox to a datagrid, set your AutoGenerateColumns="False" -- eg <asp:datagrid id="dgResult" Runat="server" AutoGenerateColumns="False"> then define the textbox: <asp:TemplateColumn HeaderText="Period Control Begin"> To bind (database) table column to textbox, in the textbox definition set: Text='<%# DataBinder.Eval(Container.DataItem,"PutNameOfColumnHere" You can reference the TextBox from the code behind as follow: dim txtBox as TextBox I hope this will help, You can also search on google for more help, Let me know if this was of any help |
Re: How Do I Edit Datagrid ? by luckyCO(m): 8:50am On Feb 06, 2007 |
Thanks for ur kind help. I don't want to bind it to any database. I want to fetch data myself and put it in datagrid just like the way one can do in MSHLfexgrid of Vb 6.0 which will enable me increase the rows and columns at my own wish. They need for binding textbox to it is to enable me type into its cells. For MSHFlexgrid if you want to add more column you just say <Name>.cols=12 or so. But have tried it in datagrid noway. I think you now know what I need. |
Re: How Do I Edit Datagrid ? by rookie(m): 11:21pm On Feb 06, 2007 |
- Am not quite familiar with MSHFlexgrid Let me clarify though, You are not actually binding to the database, but you are binding (including your textbox) to a dataset (or resultset returned - in memory). This means that you will not only have the textbox to input data, you can also prepopulate the textbox if needed. For example dim sConn as String |
Re: How Do I Edit Datagrid ? by parosky(m): 8:23am On Feb 07, 2007 |
@rookie If he talks about any of the flexgrid, it means he is using nothing beyond VB6 as those activeX controls are not in .Net. He doesn't want anything to do with database, so nothing about ADO or ADO.Net should appear in the solution that addresses his problem precisely. @LuckyCO I've always used DataGrid in VB6 just to display read only records returned from a query and any of the flexgrid when I needed to edit on the grid. I'm trying to find where I read (or got an indication) that Datagrid is read-only (and without that capability of flexgrid which I've tried out and found impossible too) so that I can be sure of what I'm saying. Check your installed MSDN library(online version seems different and unhelpful), I would have but I had problem with NEPA (prefer that name to PHCN ![]() Move on to .Net (from your contributions elsewhere in this forum I believe you are already looking into it) , there you'll find all capabilities packed into a single control (datagridview). |
Re: How Do I Edit Datagrid ? by luckyCO(m): 9:21am On Feb 07, 2007 |
parosky I think you are the one that understands my posting my posting properly. I need to make that readonly property of Datagrid to be readwrite such that I can change the rows and columns anytime I want and put data in any cell . For vb6.0 I used either Msflexgrid or MSHflexgrid. But thinking of .net I dont feel ok using COM property. That is why I want to know whther I can make the Datagrid editable Thanks |
Re: How Do I Edit Datagrid ? by parosky(m): 10:26am On Feb 07, 2007 |
@LuckyCO Well, I'll let you know if I find anything concrete. luckyCO: Meanwhile, in .Net, you don't have any business with COM as regards the issue at hand, or do you mean creating and using objects (as in OOP). It may not be as cumbersome as you think. If you need any help, esp. as regards datagridview or whatsoever let's know. |
Re: How Do I Edit Datagrid ? by rookie(m): 2:35pm On Feb 07, 2007 |
Again how can I bind Textbox control to datagrid such that I can Type in Datagrid cell using VB.Net That statement threw me off. anyhow, sorry I wasn't of too much help, Goodluck |
Re: How Do I Edit Datagrid ? by andre5(f): 12:34pm On Feb 10, 2007 |
Don’t know if you figured a way round your problem yet, but regards to your question, what you need to first understand is a datagrids data source, which could be a database, an xml file, a dataset, datatable, or collection object. When you learn to manipulate a datagrids data source you manipulate the data the grid displays. First of all I’m assuming you’re talking about windows application datagrid not web, and you’re working with VS02 or 03 and .net framework 1.x. So to programmatically add create and add data to a datagrid look at the following example. Add a datagrid on a form and add this code in the load event of the form; 'Create DataTable Dim dt As New DataTable("MyFavoriteArsenalPlayers" ![]() 'Create and add Colums Dim tColumn As DataColumn tColumn = New DataColumn("ShirtNo", System.Type.GetType("System.Int16" ![]() dt.Columns.Add(tColumn) tColumn = New DataColumn("FirstName", System.Type.GetType("System.String" ![]() dt.Columns.Add(tColumn) tColumn = New DataColumn("LastName", System.Type.GetType("System.String" ![]() dt.Columns.Add(tColumn) 'Create rows and add row data Dim row As DataRow row = dt.NewRow row("ShirtNo" ![]() row("FirstName" ![]() row("LastName" ![]() dt.Rows.Add(row) row = dt.NewRow row("ShirtNo" ![]() row("FirstName" ![]() row("LastName" ![]() dt.Rows.Add(row) row = dt.NewRow row("ShirtNo" ![]() row("FirstName" ![]() row("LastName" ![]() dt.Rows.Add(row) DataGrid.DataSource = dt ‘**************************************************** To Delete rows from the Datagrid use this code dt.Rows.RemoveAt(i) where “i” is the index of the row you want to remove. And I hope you see that I’m not maniputating the datagrid per say, but its data source. Also you said how can I bind a textbox to a datagrid, I guess u meant how to manipulate a datagrid cell. You can do that using the following code. Add a button control to the form and add this code in its click event; DataGrid1.Item(2, 1) = "Alexandra" OR Or you edit the cell within the datasource itself: Dim dt As DataTable dt = DataGrid1.DataSource dt.Rows(2)("FirstName" ![]() To bind a datasource to a Textbox look and the following code snippet; Add a 3 textboxes on a form and add this code in the load event of the form; 'Create DataTable Dim dt As New DataTable("MyFavoriteArsenalPlayers" ![]() 'Create and add Colums Dim tColumn As DataColumn tColumn = New DataColumn("ShirtNo", System.Type.GetType("System.Int16" ![]() dt.Columns.Add(tColumn) tColumn = New DataColumn("FirstName", System.Type.GetType("System.String" ![]() dt.Columns.Add(tColumn) tColumn = New DataColumn("LastName", System.Type.GetType("System.String" ![]() dt.Columns.Add(tColumn) 'Create rows and add row data Dim row As DataRow row = dt.NewRow row("ShirtNo" ![]() row("FirstName" ![]() row("LastName" ![]() dt.Rows.Add(row) row = dt.NewRow row("ShirtNo" ![]() row("FirstName" ![]() row("LastName" ![]() dt.Rows.Add(row) row = dt.NewRow row("ShirtNo" ![]() row("FirstName" ![]() row("LastName" ![]() dt.Rows.Add(row) ' make sure nothing is binded already TextBox1.DataBindings.Clear() TextBox2.DataBindings.Clear() TextBox3.DataBindings.Clear() ' bind the data to the textboxes TextBox1.DataBindings.Add("Text", dt, "FirstName" ![]() TextBox2.DataBindings.Add("Text", dt, "LastName" ![]() TextBox3.DataBindings.Add("Text", dt, "ShirtNo" ![]() ‘************************************************************* ‘Run the app Now when you bind data to a textbox you can only view one row at a time, to move to the next row you have to move the bindingcontext position to do that you have to create a CurrencyManager Object. (odd name but it has nothing to do with money) Example; Add a button control to the form and add this code in its click event; Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim PositionManager As CurrencyManager PositionManager = CType(Me.BindingContext(dt), CurrencyManager) PositionManager.Position = PositionManager.Position + 1 End Sub You will have to make dt a global variable for this section to work. Now the CurrencyManager’s Position property get's and set's the row position, so you add 1 to move forward and subtact 1 to move backwards. I hope this helps you but there are lots of other ways you can do this, but they are all easy to understand just take your time. |
Re: How Do I Edit Datagrid ? by luckyCO(m): 10:01am On Feb 12, 2007 |
Thanks I shall try that. |
(1) (Reply)
How Do You Get A CEH / Pentesting Job In Nigeria? / Laravel:call To Undefined Method Illuminate\database\eloquent\collection::save() / Is 5 Months Enough To Learn Java?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 33 |