473,388 Members | 1,606 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,388 software developers and data experts.

Programmatically assigning a value to a DataGridCell

(Type your message here)
1 - How do I programmatically assign a value to a specified cell in a DataGrid? Something like DataGrid1(3,8) = "ABC"

2 - When I am going to the last row (the empty one)in order to insert a new record into the DB, I want the default values of the fields that do have default values to be displayed when I first enter this row. How do I achieve it?
--------------------------------
From: Moshe Lupiansky

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>yvA6J0mFtUSQcmSEsmdsRg==</Id>
Nov 16 '05 #1
2 9196
1) myDataGrid.CurrentCell = New
DataGridCell(RowIndexYouWant,ColumnIndexYouWant);

2) Have you set default values for the underlying DataColums of the
DataTable? If so, they should be populating themselves when a new row is
added. For instance,
myDataSet.Tables["SomeTable"].Columns[SomeColumnIndex].DefaultValue =
"Whatever"; //In this http://www.knowdotnet.com/articles/types.html Article
I'm discussing types but the example I use is regarding defaultvalues of
DataColumns which is what you'd need.

"Whatever should appear when you add a new row or if you're using a
BindingContext, when you call .AddNew

You may also want to set the Nulltext property of your DataGridColumnStyle
if you want those values to 'appear' in the grid but not actually be there.
If you use Defaults, then "Whatever" will actually get sent back to the db
(using the above example) as SomeColumnIndex in the new row when you call
Update. If you just wanted it to say "Whatever" but not be delivered back
to the DB, then use NullText instead of default value.

HTH,

Bill

HTH,

Bill

"Moshe Lupiansky via .NET 247" <an*******@dotnet247.com> wrote in message
news:OC*************@TK2MSFTNGP09.phx.gbl...
(Type your message here)
1 - How do I programmatically assign a value to a specified cell in a DataGrid? Something like DataGrid1(3,8) = "ABC"
2 - When I am going to the last row (the empty one)in order to insert a new record into the DB, I want the default values of the fields that do have
default values to be displayed when I first enter this row. How do I achieve
it? --------------------------------
From: Moshe Lupiansky

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>yvA6J0mFtUSQcmSEsmdsRg==</Id>

Nov 16 '05 #2
Jax
In response to question one

datagrid1[0,0] = someValue

you could also do it to the datasource if you've databound it

DataView dv = new DataView(tableIMadeEarlier)
datagrid1.DataSource = dv

dv.Table.Row[datagrid1.CurrentCell.RowNumber][datagrid.CurrentCell.ColumnNumber] = someValue

jax
Nov 16 '05 #3

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

Similar topics

1
by: Jenny | last post by:
Hi, Can I create an array of tags by assigning same name to these tags? For example, I have two <p> tags with the same name t1. But document.all.b.value=document.all.t.length does not...
6
by: Tamir Khason | last post by:
How to prevent the selected cell from being editable (visual) at DataGrid? Once click on cell (even readonly) there are cursor inside it and select text appears. How to prevent it Thankx
2
by: Mohammed Abdel-Razzak | last post by:
dir sir I have a problem with the data gri I want to get the data in the selected cell and store it in a strin How can I do that??! thanks si Mohammed
2
by: Philipp Sumi | last post by:
Hello I have to start an Asp.net project that involves i18n, so I was doing some reading on the subject. I'm not sure (and I *really* hope I'm wrong) but is it true, that there is no way to...
3
by: jaYPee | last post by:
i'm wondering how can i get the value of primary key in datagrid. thanks in advance
1
by: Karl | last post by:
Hi there, I have a problem needs help. In a winform, I have a datagrid. In Mouse move event, I can get coodinates of Mouse. I want to decide which datagridcell my mouse is on. Can anybody...
3
by: Ken Fine | last post by:
I'm interested in programmatically manipulating groups of ASP.NET controls by type. Can someone suggest code for the following? Loop through, say, all label controls on a page, and assigning a...
1
by: kimkamp | last post by:
I want to create a variable name programmatically. For instance: Dim GlobVar as String = "My.STL." Dim VarName as String = "sAccountNo" Dim VarValue as String = "ABC123" I want to end up...
1
by: Bogdan | last post by:
Hi, I'm trying to programmatically assign a script to a CancelButton's OnClientClick in a wizard step. I'm doing it in ActiveStepChanged event handler. I'm also assigning scripts to finish and...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
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...
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...

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.