DataGrid programming…

Customizing the data grid (in Windows Forms) was always one of the most popular topics on the C# or VB developer centers, so I’m sure a lot of people will be interested in this article. It is in C#, so far, but if you’d like to see it in VB I’d suggest you email the writer (email at the bottom of the article).

Styling with the DataGridColumnStyle, Part 1
Explains the rendering infrastructure of the Windows Forms DataGrid control, including the various resources that the DataGrid utilizes to display its data.

Author: Duncan Mackenzie

I'm the Developer Lead for the Channel 9 team, formerly worked on MSDN as a developer, content strategist and author.

147 thoughts on “DataGrid programming…”

  1. Dear
    have a good day!

    I’m a student programmer using visual basic, may you help me to put dropdown like combobox in datagrid and put all the data from my database.
    please send me sample code or program about this.

    thanks

    Rogie Paulo
    rogiepaulo@yahoo.com

  2. hi, if you’re looking for a solution to add a control into datagrid’s cell, you’ll found a lot. I’ve got problem when adding a combobox into grid, following MSDN’s sample code, codeproject …, there is no perfect solution until I found a great a http://www.datagridstyles.com, check it out. Oh, forgot telling the problem when adding combobox, the adding is ok but when you enter that combobox, that combobox doesn’t act as a normal combobox: problem when I enter the combobox by pressing Tab (it moves to next cell), pressing up or down arrow key 🙂

  3. hai

    i want to design a gatagrid where we should enter data and it should get updated in back end …and each column should get binded as soon as it mouse click is on another column…

    its me
    mahiban

  4. hi im trushar
    i have proble in datagrid about how to add dropdown ,calendar,textbox in datagrid
    how to update,edit and add rows in those data grid .. how to create a blank datagrid in page loade
    send me sample code about detail…
    tx

  5. hi im vinu
    i have proble in datagrid about how to add dropdown ,calendar,textbox in datagrid
    how to update,edit and add rows in those data grid .. how to create a blank datagrid in page loade
    send me sample code about detail…
    tx

  6. Dear
    i am programer and i want to know , how to control the cell of datagrid as individaul cell. so how can i put ex, textbox in the cell of datagrid and handel the textbox with all events ,by c# if you can please if you know please send me

    mail Id:- prabhu_7772003@yahoo.co.in

  7. friend,

    I have to display total value “sum(datagrid_column_name)” into textbox from datagrid cell.

    Another one, can we display the aggregate function into datagrid?
    If possible , please reply

    please reply me

  8. Buenas tardes

    Me podrian ayudar necesito realizar una pequeña evaluacion de preguntas en visual basic.net y necesito trabajar con datagrid y checbox y desde ahi seleccionar las respuestas y mediante eso realizar una evaluacion y mostrar cuantas preguntas fueron acertadas
    Gracias por la atencion prestada

  9. Hi I am looking for the datagrid code, I would really appreciate it, if you could please email me at zindagi11@rediffmail.com
    and also can you tell me how do I display the total at the bottom if one of the rows in the grid has to be calculated.

    Thanks,
    Farooque.

  10. Hi,
    I am a porgrammer in asp.I have a problem.I am working on datagrid in which i used template for textbox when the user enters values in this text box and goes to another ,this value should be stored in another page .and when that user comes back to previous page the values should be seen .I am able to display values in another page but when user comes back the values are not seen in text box of datagrid.Can anyone help me in doing this.This is urgent.

    Thanks
    Deepu

  11. i am R & D Developer and i want to know , how to control the cell of datagrid as individaul cell. so that i can use it in my project ,by using c# if you know please send me

  12. i want a datgrid with a textbox in in . i want to populate that textbox from the database and then modify the content in the database and it should be saved to database.
    i want it in vb.net code format.

  13. i want a datgrid with a textbox in in . i want to populate that in the textbox of the datagrid with the values from the database and then modify the content in the text box of the datagrid and it should be saved to database.
    i want it in vb.net code format.

  14. i want a datgrid with a textbox in it . i want to populate that in the textbox of the datagrid with the values from the database and then modify the content in the text box of the datagrid and it should be saved to database.
    i want it in vb.net code format.please mail to me:sridharhere@gmail.com

  15. Hi,
    My Name Is Shrikant More .I am .Net Developer.

    Can Any One Provide me With The Code For

    adding checkbox control in the datagrid for each record & how to implement the checkall function using VB.NET .

    Regards,
    Shrikant More

  16. Hi I need some help in Datagrid.

    How to add the new rows to the datagrid at the specified locations.
    How to remove a specific column.
    How to set alternate color for the rows.

    using visual basic.net

    thanks in adavance

  17. in vb .net (Datagrid) i want to make calculation like Qty * Price and put result in another cell
    also how to put the cursor in another cell like set focus in Access
    I have to display total value “sum(result_column)” into textbox from datagrid cell.

    mbalafreet@hotmail.com

  18. hello
    i am programmer, i want to know how do working with data grid in visual basic for add,edit,delete and display the records using ADO connection not Adodc control,
    please send me the coding to my e-mail

    hassanm@anwal.com

  19. Hey, how’s it going.
    I am using a listview in a program that I have been working on. The listview is great for most of my needs but there are some deficiencies that make me feel that a better control is needed. I am interested in transferring the code over to a Datagrid. Haven’t worked on Datagrids at all. Perhaps your Datagrid article would shed some light. Would you be kind enough to send me your code article in VB.net so that I can see if a Datagrid will be a better choice? Thanks.

  20. hi all,
    i am new to vb.net and i need a urgent help from all the guys here please help me….

    i want to add a datagrid to the form and i wannt to fill-up some datas manualy and i want to put coloum caption and clumn values on my way like vb6

    can any one please help me

    najath
    najath@onlnet.com

  21. Since we are using ItemDataBound event to to total up the price column in the data grid, we have to specify on the web form (.aspx) page, the method that would handle the ItemDataBound event (Event wiring). This is acheived by mentioning within the datagrid control tag that on the occurence of the event

    (OnItemDataBound), itemDataBound method should be called.

    <asp:datagrid id=”dg” runat= “server”< /FONT> OnItemDataBound=”itemDataBound” ShowFooter=”True”>

    On the code behind file (.aspx.cs), we define the ‘itemDataBound’ method for handling the ItemDataBound Event.

    float total = 0; protected void itemDataBound(object sender, DataGridItemEventArgs e) { if (e.Item.ItemType!=ListItemType.Header && e.Item.ItemType!=ListItemType.Footer) {
    &nbs p; total += float.Parse(e.Item.Cells[1].Text);
    e.Item.ForeColor = System.Drawing.Color.Blue;
    }
    else if (e.Item.ItemType == ListItemType.Footer)
    {
    e.Item.Cells[0].Text = “Total”;
    e.Item.Cells[1].Text = total.ToString();
    }
    }

  22. hi
    i am a software programmer
    recently joined one organization
    i want to how to add checkbox to datagrid in each row of column using asp.net through property builder & add template column & in the template column write in the header text
    <input type=checkbox name=”c1″>
    but only came into the header only
    but i want to come all fileds
    how……….
    in that manner only through property builder not coding

  23. please send me the code for how to select a check boxes in datagrid if i select the multiple checkboxes in datagrid that selected checkboxes items to move to another datagrid

  24. hi there..plz help me,is it possible to put a text in the row header of the datagrid? plz give send me a sample program. thanks in advance

    Musika

  25. I’m using visual basic.net, may you help me to put a combobox in datagrid and put all the data from my database.

    please send me sample code or program about this.

  26. friend,

    I have to display total value “sum(datagrid_column_name)” into textbox from datagrid cell.

    Another one, can we display the aggregate function into datagrid?
    If possible , please reply

    please reply me

  27. Hi,
    I am vb.net programmer. I am having a dataset with fields Date_Time, Gen_Unit_no & Generation. i want guidlines for a editable datagrid in which left most coloumn should be Date_Time filled with 15 min interval for a dat from 00:00 hrs mid night to 23:45 hrs. For all other right hand side coloumns against the Date_Time coloumn, user should be able to edit or enter generation data up to 23:45 hrs for each of the unit_no field. The interface i am trying to build is like below:

    Dat_Time Unit_No Unit_No Unit_No

    Time_Value Genration Generation Generation
    Time_Value Genration Generation Generation
    Time_Value Genration Generation Generation

    Please explain the procedure.

    Surya Prakash – prakashsps@hotmail.com

  28. ‘Declare variable
    Dim grdCombo As New DataGridViewComboBoxCell
    ‘Set style
    grdCombo.Style.ForeColor = Color.CornflowerBlue

    grdCombo.Items.Add(“items”)

    you can use gotfocus or any other event of the datagridview (according to your requirement) for working

  29. ‘Function for filling combo in datagridview

    Private Function FillCombo() As DataGridViewComboBoxCell

    Dim reader As SqlDataReader
    Dim grdCombo As New DataGridViewComboBoxCell

    grdCombo.FlatStyle = FlatStyle.Popup
    grdCombo.DropDownWidth = 170
    grdCombo.Style.ForeColor = Color.CornflowerBlue

    SQLCmd.CommandText = “SELECT * from tablename”
    SQLCmd.CommandType = CommandType.Text
    reader = SQLCmd.ExecuteReader

    While reader.Read
    grdCombo.Items.Add(reader(“item 1″) & ” ” & reader(“item 2”))
    End While

    reader.Close()
    reader = Nothing

    Return grdCombo
    End Function

    then

    grdJournal.Item(colIndex, grdJournal.Rows.Count – 1) = FillCombo()

    you can trace me at mrtanvirali@hotmail.com

  30. Dear all,
    can anyone give the solution of customizing gatarid’s row individually…means each row of a datagrid can b customizable.
    exampl: input: row no,color
    output : desired view.

    its urgent..
    if poss send a solution.
    Ankan

  31. hi
    i am a trainee level programmer in avni at chennai.i could not add the check on the datagrid pls help me question is”how to add check box on the datagird control using asp.et(c#)and if click the check box it shouled show some controls”

  32. I’m a programmer in Vb.net.
    I want a sample code of how to edit rows in a datagrid and thereby save the changes.Plz help me regarding the same by mailing me the code.Thanks

  33. Dear programmers,

    I am beginner programmer ,want to connect VBNET with SQL Server.Please give me hint to use datagrid as data entry form to MY SQL database Server.

    Denny

  34. How to enter data into a datagrid.
    how to put textbox and combobox in a datagrid
    may you help me to put dropdown like combobox in datagrid and put the selected data from the combobox to datagrid
    please send me sample code or program about this.
    thanks in advance
    Email me at vijiajai@hotmail.com

  35. Hi
    I am an indian from a’bad need a code in VB.NET that how to add buttons,combobox and checkbox in Datagrid control as I am new and have just started VB.Net. If you please do for me i shall be highly thankful for you.

    Thank You
    Khushi

  36. Dim conn As SqlConnection = New SqlConnection(“server=L118;database=kanwar_db;uid=sa;pwd=;”)
    Dim dt As DataTable

    Dim dset As New Dataset1
    dt = dset.Tables(“Bill”)
    DataGrid1.DataSource = dt
    here Bill is the table which we have created in database.

  37. in vb .net (Datagrid) i want to make calculation like Qty * Price and put result in another cell
    also how to put the cursor in another cell like set focus in Access
    I have to display total value “sum(result_column)” into textbox from datagrid cell.

  38. hi,
    in vb .net (Datagrid) i want to make calculation like Qty * Price and put result in another cell
    also how to put the cursor in another cell like set focus in Access
    I have to display total value “sum(result_column)” into textbox from datagrid cell.

    My Email Id
    sathiya_jeba@yahoo.co.in

  39. How to enter data into a datagrid.
    how to put textbox and combobox in a datagrid
    may you help me to put dropdown like combobox in datagrid and put the selected data from the combobox to datagrid
    please send me sample code or program about this.
    thanks in advance

  40. how to add function in datagrid when we use table n want to add container value.reply soon
    what I did
    onclick=<%func_open(#Container.DataItem (“value”))%>”

  41. How can I put values to a datagrid from a textbox while clicking a button.
    And how can specify the title for each column in a datagrid.
    Thanks

  42. i am a Programmer usinf ASP.NET. may you help for In ASP.NET How to Put a textbox or Combobox in datagrid?
    Please send me sample code or solutions
    thank you

  43. _ when argument of functions is changed, functions are calculated automatically. May you help me to program this function in data grid (or textbox) in VB.NET.
    _ I don’t know how to grogram function drawing a line in data grid in VB.NET.
    please send me sample code or program about this.
    I ‘ m looking forward you

    Thank you very much.

  44. Hi there, I want the code for database connectivity from SQLConnection to connect it with MsFlexGrid to fill it with records of the table in the grid and how to fetch the particular record from the grid and fill that record in the text boxes. I have done code in VB6.0 for MSHFlexGrid , but I dont know the code of MsFlexGrid in VB.net 2003

  45. i’m a student programmer working in asp.net with vb.
    i like to know the code…..
    as such datagrid will display all the records from database.i want to display only particular record whenever i select a particular item corresponding to the record..from the dropdownlist…

  46. Hai!
    I am using asp.net for my project. I need to know the method of fetching datas to a dropdown control within a datagrid in asp. net. Just send me the source code clearly describing it with an example. Mail it to my above mentioned mail id. I will be glad

  47. i want to save first record in the database through footer in datagrid with asp.net c#, it gives error as “out of range or must be non negative”, when there is no record avilable in database’s table. When there is any records in my database’s table then it works properly. plz give solution

  48. Dear sir
    Please send to me the solution of following probloem

    How to put a databound ComboBox in a Column of a Datagrid ?

    I want to this solution in visual basic 6.0 professional. Please send solution to to me with article.
    Thanks

  49. can anyone tell me how to highlight particular boxes in datagrid when any condition “like any sql query ” is matched.. I m new to VB.NET
    Thanks

  50. Hi,
    I am programmer using VB.Net 2005, may you help me to how to retrive value in Checkbox in DataGrid like GridView. Please send me code or program about this.

    Thanks,
    Muthu kumar.

  51. Hello i m Abhijeet I want C# code for displaying Sum of values from Column of DataGrid into the Footer template of each column .Here DataGrid is not Binded to database but it is binded to DataSet. I have 4 Columns in DataGrid all r Template Columns .Please Send me Code
    Thank u.

  52. hi am srinivasa goud.g
    tinku.
    am looking for sql server reporting tools please refer any good tool for sql server Or Oracle.

  53. GoodDay

    I’m a graduate developer using VB.NET, may you help me to put dropdown like combobox in datagrid and put all the data from my database.
    please send me sample code or program about this.

    thanks

    Sibongiseni Ntombela

  54. hi,

    i want to add checkbox into datagrid and retrieve only those rows in dataGrid that i have put checked in checkbox in vb.net, please reply

Leave a Reply

Your email address will not be published. Required fields are marked *