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

How programaticly change row in a GridView?

Hi!

I have used the SqlCommand and DataReader to read data to a DataSet
This dataset is the used to set the properties; DataMember and DataSource of
the DataGridView.

Now what i want to do is to go to a specific row of the DataGridView.
I have tried to use a BindingSource to find the value and the issue a
position, but it doesn't work

What i want to do is when i acces the grid wich is called as a prompt i want
to position my self on the value based on the field that i call the lookup
from....

Regards
Martin
Nov 9 '06 #1
4 11671
Martin,

You are making a message that is very confusing,
Are you writing in your subject about a GridView and therefore a
WebApplication and therefore using a datareader, or are you talking as in
your text about a DataGridView and therefore a windowforms application and
confuse us even more that you are not using a dataadapter or tableadapter to
get the dataset.

(By the way, in a webapplication it would in my idea as well more efficient
to use the two last ones, to be sure your dataset is correct and the
positioning using the bindingsource goes well).

So maybe can you help us to come out of this confusing things?

Cor

"Martin Arvidsson" <ye*******@ms.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi!

I have used the SqlCommand and DataReader to read data to a DataSet
This dataset is the used to set the properties; DataMember and DataSource
of the DataGridView.

Now what i want to do is to go to a specific row of the DataGridView.
I have tried to use a BindingSource to find the value and the issue a
position, but it doesn't work

What i want to do is when i acces the grid wich is called as a prompt i
want to position my self on the value based on the field that i call the
lookup from....

Regards
Martin

Nov 10 '06 #2
Hi!

Sorry it should be DataGridView...

Here is a code snippet how it looks today
I use this form to select a value from a table. If a value is already in the
calling TextBox, i want to
place the "cursor" on the row in the lookup form
/Martin

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ControlDBLookup
{
public partial class Lookup : Form
{
private string TableSchema;
private string TableName;
private SqlConnection conn;
private string[] DisplayColumns;
private DataSet LookupData;
private DBLookup theLookup;
public string Lookup_TableSchema
{
set { TableSchema = value; }
}
public string Lookup_TableName
{
set { TableName = value; }
}
public SqlConnection Lookup_SqlConnection
{
set { conn = value; }
}
public string[] Lookup_DisplayColumns
{
set { DisplayColumns = value; }
}
public DataSet Lookup_LookupData
{
get { return LookupData; }
}
public Lookup(DBLookup ALookup)
{
InitializeComponent();
theLookup = ALookup;
}
private void Lookup_Load(object sender, EventArgs e)
{
if (conn != null)
{
DBHelper db = new DBHelper(conn);
LookupData = db.GetLookupData(TableSchema, TableName, DisplayColumns);
if (LookupData != null)
{
gvLookupData.DataSource = LookupData;
gvLookupData.DataMember = LookupData.Tables[0].TableName;
}
}
}
private void btnOK_Click(object sender, EventArgs e)
{
theLookup.ValueData = gvLookupData.CurrentRow.Cells[0].Value;
this.Close();
}

}
}

"Cor Ligthert [MVP]" <no************@planet.nlskrev i meddelandet
news:eS**************@TK2MSFTNGP03.phx.gbl...
Martin,

You are making a message that is very confusing,
Are you writing in your subject about a GridView and therefore a
WebApplication and therefore using a datareader, or are you talking as in
your text about a DataGridView and therefore a windowforms application and
confuse us even more that you are not using a dataadapter or tableadapter
to get the dataset.

(By the way, in a webapplication it would in my idea as well more
efficient to use the two last ones, to be sure your dataset is correct and
the positioning using the bindingsource goes well).

So maybe can you help us to come out of this confusing things?

Cor

"Martin Arvidsson" <ye*******@ms.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Hi!

I have used the SqlCommand and DataReader to read data to a DataSet
This dataset is the used to set the properties; DataMember and DataSource
of the DataGridView.

Now what i want to do is to go to a specific row of the DataGridView.
I have tried to use a BindingSource to find the value and the issue a
position, but it doesn't work

What i want to do is when i acces the grid wich is called as a prompt i
want to position my self on the value based on the field that i call the
lookup from....

Regards
Martin


Nov 10 '06 #3
I have the same question. I have a windows form with a DataGridView, which I
want to programatic to set the row.

"Martin Arvidsson" wrote:
Hi!

Sorry it should be DataGridView...

Here is a code snippet how it looks today
I use this form to select a value from a table. If a value is already in the
calling TextBox, i want to
place the "cursor" on the row in the lookup form
/Martin

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ControlDBLookup
{
public partial class Lookup : Form
{
private string TableSchema;
private string TableName;
private SqlConnection conn;
private string[] DisplayColumns;
private DataSet LookupData;
private DBLookup theLookup;
public string Lookup_TableSchema
{
set { TableSchema = value; }
}
public string Lookup_TableName
{
set { TableName = value; }
}
public SqlConnection Lookup_SqlConnection
{
set { conn = value; }
}
public string[] Lookup_DisplayColumns
{
set { DisplayColumns = value; }
}
public DataSet Lookup_LookupData
{
get { return LookupData; }
}
public Lookup(DBLookup ALookup)
{
InitializeComponent();
theLookup = ALookup;
}
private void Lookup_Load(object sender, EventArgs e)
{
if (conn != null)
{
DBHelper db = new DBHelper(conn);
LookupData = db.GetLookupData(TableSchema, TableName, DisplayColumns);
if (LookupData != null)
{
gvLookupData.DataSource = LookupData;
gvLookupData.DataMember = LookupData.Tables[0].TableName;
}
}
}
private void btnOK_Click(object sender, EventArgs e)
{
theLookup.ValueData = gvLookupData.CurrentRow.Cells[0].Value;
this.Close();
}

}
}

"Cor Ligthert [MVP]" <no************@planet.nlskrev i meddelandet
news:eS**************@TK2MSFTNGP03.phx.gbl...
Martin,

You are making a message that is very confusing,
Are you writing in your subject about a GridView and therefore a
WebApplication and therefore using a datareader, or are you talking as in
your text about a DataGridView and therefore a windowforms application and
confuse us even more that you are not using a dataadapter or tableadapter
to get the dataset.

(By the way, in a webapplication it would in my idea as well more
efficient to use the two last ones, to be sure your dataset is correct and
the positioning using the bindingsource goes well).

So maybe can you help us to come out of this confusing things?

Cor

"Martin Arvidsson" <ye*******@ms.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi!

I have used the SqlCommand and DataReader to read data to a DataSet
This dataset is the used to set the properties; DataMember and DataSource
of the DataGridView.

Now what i want to do is to go to a specific row of the DataGridView.
I have tried to use a BindingSource to find the value and the issue a
position, but it doesn't work

What i want to do is when i acces the grid wich is called as a prompt i
want to position my self on the value based on the field that i call the
lookup from....

Regards
Martin


Feb 7 '07 #4

The DataGridItem object (which is a row on the grid) has the
DataSetIndex property. If you have the dataset that binds to the grid
at the time, use this index to access the row

If not, to get to the row, the more efficient way is use the Select
method on the Table object, not using the view.

To do this,
Define primary key on your table object.
Save the primary key value some where in your app
When need the row, do query on the table based on your primary key

some sample code:

//Define primary key on table
MyTable.PrimaryKey = new DataColumn[] {MyTable.Columns["ID"]};

//Access the row
DataRow[] rows = MyView.Table.Select("ID = " + rowID.ToString());

HTH,
Quoc Linh

Feb 7 '07 #5

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

Similar topics

2
by: Yannick Turgeon | last post by:
Hello all, I'm (still) using A97. I'd like to save/export a table (a link to a SS2000 table) in dBASE 5 format, programaticly using VBA. Is that possible? I'm currently doing it by hand but...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
1
by: Sharon | last post by:
Hello All, I have a gridview control in webform which is dynamically populated on page startup with a query. I was trying to change the header text for the columns and also set wrap to false. i...
1
by: gary.comstock | last post by:
We have a non asp web page that contains a hyperlink which opens an iframe. The iframe is hidden until the hyperlink is selected then javascript toggles the visibility to 'visible'. Inside the...
10
by: schneider | last post by:
I'm looking for a way to programaticly call a method from a different object and associate the two objects at runtime. Example: Object A exist and is unknow, I want object B to be able to call a...
1
by: =?Utf-8?B?SGFycnkgS2Vjaw==?= | last post by:
I have a GridView control with a few columns declared directly in the aspx file. I have found that if I remove the HeaderText property from all columns that the GridView handles state completely...
3
by: pvong | last post by:
VB.NET How do you change a gridview from Update mode to normal mode? I'm usually dealing for Formviews and there is a ChangeMode option but I don't see one for Gridviews.
3
by: Laila2008 | last post by:
Hi, I am trying to update data and highlight updated row in a GridView. To change the data I loop through the dataset, find the row I want, set the new data and call DataBind() on the GridView....
1
BeemerBiker
by: BeemerBiker | last post by:
I converted an arraylist to a dataset and bound the dataset to a gridview but I cannot change the value of the checkbox in the gridview. I identified the DataKeyNames and made sure that ReadOnly was...
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.