473,397 Members | 2,116 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,397 software developers and data experts.

Adding datagrid rows programmically

Hello,
I've got a datagrid with two columns and no data. I want
to add data programmically (from DB).
When I try to use sintax like:
dataset.Tables("Department").Rows(0).Item("Percent age
Used") = 10
(you can assume the grid is binded to this dataset table)

I get an error telling me row 0 does not exist. I'm
assuming I need to use a New command to add rows in a
datagrid programmincally. How would I do this? whats the
syntax?

My second question is: One of the columns is a comboBox.
Can I still use methods like Findstring and set properties
like SelectedIndex=-1 even though its in a datagrid. If
not how can I select an item in the combobox that is in
the datagrid programmically?

Thank you.
Nov 20 '05 #1
1 1460
Hi,

You have to create a new row then add it to the dataset.
Dim dr As DataRow = dataset.Tables("Department").NewRow

dr.item("Percentage Used") = 10
dataset.Tables("Department").Rows.Add(dr)

Ken

------------------
"Sebastian Santacroe" <ss*********@ilogic.com> wrote in message
news:04****************************@phx.gbl...
Hello,
I've got a datagrid with two columns and no data. I want
to add data programmically (from DB).
When I try to use sintax like:
dataset.Tables("Department").Rows(0).Item("Percent age
Used") = 10
(you can assume the grid is binded to this dataset table)

I get an error telling me row 0 does not exist. I'm
assuming I need to use a New command to add rows in a
datagrid programmincally. How would I do this? whats the
syntax?

My second question is: One of the columns is a comboBox.
Can I still use methods like Findstring and set properties
like SelectedIndex=-1 even though its in a datagrid. If
not how can I select an item in the combobox that is in
the datagrid programmically?

Thank you.

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
2
by: Praveen Balanagendra via .NET 247 | last post by:
here is the source code private void AddRow() { TableCell tc = new TableCell(); tc.Controls.Add(new LiteralControl("NewRow")); DataGridItem di = new...
2
by: Bob Hollness | last post by:
Hi group. I am a newbie to ASP.NET as you will see from some of the questions I may ask! I have a datagrid which I have populated from a database. It works great! I have added a column, via...
2
by: Agnes | last post by:
I set my datagrid's datasource programmically . However , as the form load, I found that every column width is the same, Question 1) How can i adjust it programmically ??? Question 2) I need to do...
3
by: Jim | last post by:
I have a datagrid with a DataAdapter as the DataSource. The user fills in their data for 3 columns and I want to programically add a value to the 4th (invisible) column (employee number). That way...
2
by: Flack | last post by:
Hey guys, I have a DataGrid and DataTable field in my class : private ImageDataGrid dataGrid1; //ImageDataGrid extends dataGrid and just overides OnMouseDown private DataTable dt = new...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.