473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Unbound Datagridview

9
VB.2005 - Please help - I've been trying for days to find some simple code samples to programatically add and remove data from an unbound Datagridview. I only have 3 coloums of 3 rows and there should be no editing by the user, except to click a checkbox. All other data is added by the program. I can create the coloumns and the rows OK but cant seem to get data in and out of the cells. Any pointers would be appreciated.
Dec 6 '07 #1
6 2284
Plater
7,872 Expert 4TB
When adding data to Rows, you need to index by column, not by integer(for some reason the data doesn't get in there if you use integer indexing)
Dec 6 '07 #2
Frinavale
9,735 Expert Mod 8TB
VB.2005 - Please help - I've been trying for days to find some simple code samples to programatically add and remove data from an unbound Datagridview. I only have 3 coloums of 3 rows and there should be no editing by the user, except to click a checkbox. All other data is added by the program. I can create the coloumns and the rows OK but cant seem to get data in and out of the cells. Any pointers would be appreciated.
Could you please post the code you have for creating the DataSource for your GridView.
Dec 6 '07 #3
Plater
7,872 Expert 4TB
For a given DataGridView that already has columns assigned to it:
Expand|Select|Wrap|Line Numbers
  1. //create a new row with the correct columns
  2. int newRowIDX = dgvBOMConnections.Rows.Add();
  3. //reference that row
  4. DataGridViewRow dr = dgvBOMConnections.Rows[newRowIDX];
  5. //add data to the row's "cells"
  6. dr.Cells["myStringColumn"].Value = "some value";
  7. dr.Cells["myIntColumn"].Value = 12;
  8. dr.Cells["myBooleanColumn"].Value = False;
  9.  
Dec 6 '07 #4
Frinavale
9,735 Expert Mod 8TB
For a given DataGridView that already has columns assigned to it:
Expand|Select|Wrap|Line Numbers
  1. //create a new row with the correct columns
  2. int newRowIDX = dgvBOMConnections.Rows.Add();
  3. //reference that row
  4. DataGridViewRow dr = dgvBOMConnections.Rows[newRowIDX];
  5. //add data to the row's "cells"
  6. dr.Cells["myStringColumn"].Value = "some value";
  7. dr.Cells["myIntColumn"].Value = 12;
  8. dr.Cells["myBooleanColumn"].Value = False;
  9.  
I think that the problem is that the OP does not have any columns in the GridView.
I think they're creating a custom Table or other data source to the GridView and not properly binding it to the data.
Dec 6 '07 #5
Plater
7,872 Expert 4TB
I think that the problem is that the OP does not have any columns in the GridView.
I think they're creating a custom Table or other data source to the GridView and not properly binding it to the data.
Frinny makes a good point, It might be easier if you set up a DataTable object to be how you want it (3 Rows/columns etc) and fill that with data, THEN bind it to the DataGridView, rather then edit the contents of the DataGridView directly.

Perhaps it would be helpfull if you posted the code you are using?
Dec 6 '07 #6
Unter
9
Thanks so much for the response everyone - this is the stripped down code
The problem is the combobox values

Expand|Select|Wrap|Line Numbers
  1.   Dim dropcolumn As New DataGridViewComboBoxColumn
  2.         Dim CheckColumn As New DataGridViewCheckBoxColumn
  3.         Dim CheckColumn2 As New DataGridViewCheckBoxColumn
  4.  
  5.     Dim i As Integer = 0
  6.                 Dim temp As String = ""
  7.  
  8.     With dropcolumn
  9.                      .Name = "Something1"
  10.                      .HeaderText = "     Something1"
  11.                          For i = 0 To 255
  12.                               temp = array(i)
  13.                                  If temp = "U" Then
  14.                                      .Items.Add("Stock" + Str(i))
  15.                                  End If
  16.                          Next
  17.                      End With
  18.  
  19.                     With CheckColumn
  20.                        .Name = "Something2"
  21.                        .HeaderText = "  Something2"
  22.                     End With
  23.  
  24.                  With CheckColumn2
  25.                     .Name = "Something3"
  26.                     .HeaderText = "  Something3"
  27.                  End With
  28.  
  29.         DG1.Columns.Insert(0, dropcolumn)
  30.         DG1.Columns.Insert(1, CheckColumn)
  31.         DG1.Columns.Insert(2, CheckColumn2)
  32.  
  33.         Dim Null_String As String = ""
  34.         With Me.DG1.Rows
  35.             .Add(Null_String)
  36.         End With
  37.  
  38.         DG1.Rows(0).Cells(1).Value = True
  39.         DG1.Rows(0).Cells(2).Value = True
This seems to work fine although I'm not sure why I need the null_string but
without it I get the error that the following lines are out of range.

My problem is when I want to add or remove items from the combobox.
Once the users has chosen an item from the combobox I need it removed
so it cant be chesen again.

dropcolumn.Items.Remove("ITEMNAME")
dropcolumn.Items.Remove(index)

Seems to have no effect - but no errors either

Even rerunning

.items.clear
For i = 0 To 255
temp = array(i)
If temp = "U" Then
.Items.Add("Stock" + Str(i))
End If

Doesnt effect the combobox contents

Hope this is clearer, thanks again
Dec 9 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dm1608 | last post by:
Hello, I have a DataGridView control in VB.NET 2005 that I would like to iterate thru row by row and parse out the individual columns into variables. Can someone provide me example code or direct...
2
by: inpuarg | last post by:
Is it possible that - or is there any workarround for adding a new unbound row to a datagridview at bound mode ? Theese are not working. And i don 't want to add a row to dataset then rebind -...
7
by: Max | last post by:
I've included the needed tables in the DataSource. Those tables that are bound to controls I can workwith. But how do you get access to the DataAdaptors that are not bound? me.Dataset1.table...
0
by: MethMath | last post by:
I have an unbound DataGridView which I programatically feed new rows. As I want to maintain possibility for user to add additional rows manually I maintain AllowUserToAddRows=True, but when a row...
3
by: Aspnot | last post by:
I have a form that is setup in a Master/Detail configuration. The Detail section is represented with a DataGridView. Some of the columns in this DataGridView control are unbound. When a user...
7
by: Rainer Queck | last post by:
Hi NG, Why is it, that in my DataGridView all columns which are not bound to a "DataProperty" loos thier content in a couple of occasions? This happens if: - Underlaying...
1
by: Martin | last post by:
Hi, I'm having a problem with a datagridview control when trying to read the value of an unbound checkbox cell. The code below works fine if I click on any text cell, bound or unbound, and...
2
by: =?Utf-8?B?QnJhZA==?= | last post by:
ok, vs2005 and vb.net i have an unbound datagridview control i am programatically adding data to it the DataGridView.Rows.Add() function does not always add rows to the end of the grid...
4
by: Anthoni | last post by:
Dear All, I need to export data of unbound datagridview to XML file. Since my DataSource is NULL, What other options do I have? Does i need to make 2 loops (on all the records and inside loop of...
0
by: Ed Bitzer | last post by:
Appreciate some direction on populating an unbound DataGridView with an one dimensional array of date an appointments (a calendar) read from a coma delimited text file. My original approach was to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.