|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
datagrid entry with no db componentsHi,
How can I insert an entry to datagrid without using db components? For example, I have a textbox and I would like to press OK button and insert the text in textbox to datagrid. Regards. Hi you need a datatable for that,
for example: Dim dt As New DataTable("MyTable") dt.Columns.Add("Name") dt.Columns.Add("Country") Datagrid1.DataSource = dt.DefaultView you then can add rows with a datarow object or with dt.LoadDataRow(New Object() _ {"Peter", "Belgium"}, True) dt.LoadDataRow(New Object() _ {"Cor", "The Netherlands"}, True) dt.LoadDataRow(New Object() _ {"Ken", "USA"}, True) dt.LoadDataRow(New Object() _ {"You", Textbox1.Text}, True) Hope this helps Greetz Peter -- Show quoteHide quoteProgramming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. (Rich Cook) <mhmtz***@gmail.com> schreef in bericht news:1139818599.729279.265010@g14g2000cwa.googlegroups.com... > Hi, > > How can I insert an entry to datagrid without using db components? For > example, I have a textbox and I would like to press OK button and > insert the text in textbox to datagrid. > > Regards. > Hi, you can use a DataGridTableStyle and DataGridTextBoxColumn for that (see
code below) Hope this helps Greetz Peter Dim dt As New DataTable("MyTable") dt.Columns.Add("Name") dt.Columns.Add("Country") Dim ts1 As New DataGridTableStyle ts1.MappingName = "MyTable" 'Has to be the same as the table name Dim TextCol As DataGridTextBoxColumn For i As Integer = 0 To dt.Columns.Count - 1 TextCol = New DataGridTextBoxColumn Select Case i Case 0 TextCol.Width = 50 TextCol.Alignment = HorizontalAlignment.Center TextCol.HeaderText = dt.Columns(i).ColumnName Case 1 TextCol.Width = 100 TextCol.Alignment = HorizontalAlignment.Center TextCol.HeaderText = dt.Columns(i).ColumnName TextCol.NullText = "" End Select TextCol.NullText = "" TextCol.MappingName = dt.Columns(i).ColumnName ts1.AllowSorting = False ts1.GridColumnStyles.Add(TextCol) Next DataGrid1.TableStyles.Clear() DataGrid1.TableStyles.Add(ts1) DataGrid1.DataSource = dt.DefaultView dt.LoadDataRow(New Object() _ {"Peter", "Belgium"}, True) dt.LoadDataRow(New Object() _ {"Cor", "The Netherlands"}, True) dt.LoadDataRow(New Object() _ {"Ken", "USA"}, True) dt.LoadDataRow(New Object() _ {"You", "Your Country"}, True) Hi Peter,
Thanks for your time and helps. Last question: Is it possible to use combobox on datagrid? For example I want to add the values to be selected from the combobox manually. Best Regards. Hi have a look at these
http://www.vb-tips.com/default.aspx?ID=1eb83247-7464-467e-a9dd-faf92f41f563 http://www.vb-tips.com/default.aspx?ID=af5ec1a9-bd98-4556-adf9-3866d4936de0 Greetz Peter -- Show quoteHide quoteProgramming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. (Rich Cook) <mhmtz***@gmail.com> schreef in bericht news:1139906993.777149.157140@g14g2000cwa.googlegroups.com... > Hi Peter, > > Thanks for your time and helps. > > Last question: Is it possible to use combobox on datagrid? For example > I want to add the values to be selected from the combobox manually. > > Best Regards. >
Local Machine policy exceptions
VB.NET or C#.NET ??? reading text files control disable byref and byvalue Open a text file and into an array ?? Usual Databinding Question - UNusual Requirements Must I change the property in 26 projects or is there a soultion level way of doing it Best way to display 4 rows / 4 columns pass to background thread |
|||||||||||||||||||||||