473,597 Members | 2,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get DataGrid Cell Content After Intial Sort

I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's
reflect the contents of the grid cells.

Sorting of columns (both thru VS and programmaticall y) work fine except,
when the form/grid first opens up and the grid is immediately sorted the TB
don't reflect the sorted data of the First row of the grid.

Note: Initially the black grid indicator arrow points to the first row. If
the user choses another row and then sorts the TB's reflect proper data.

//setGridSort(Dat aSet dataSet, DataGrid dataGrid, string
sortTableColumn Name, int tableNo)
DataView dataView = createNewDataVi ew();
dataView = dataSet.Tables[tableNo].DefaultView;
dataView.Sort = sortTableColumn Name;
dataGrid.DataSo urce = dataView;

//incorrect - not the correct cell value of the grid for the TB
numberTB.Text = (string) (dataGrid[dataGrid.Curren tRowIndex, columnNo]);

Steve

Nov 16 '05 #1
4 2826
Steve,

Are you setting up the data binding correctly? Is the data source that
you are connecting the grid to the same as the data source that you are
binding the textboxes to?

Can you show a piece of code that shows the issue?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Steve B." <St****@discuss ions.microsoft. com> wrote in message
news:52******** *************** ***********@mic rosoft.com...
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's
reflect the contents of the grid cells.

Sorting of columns (both thru VS and programmaticall y) work fine except,
when the form/grid first opens up and the grid is immediately sorted the
TB
don't reflect the sorted data of the First row of the grid.

Note: Initially the black grid indicator arrow points to the first row. If
the user choses another row and then sorts the TB's reflect proper data.

//setGridSort(Dat aSet dataSet, DataGrid dataGrid, string
sortTableColumn Name, int tableNo)
DataView dataView = createNewDataVi ew();
dataView = dataSet.Tables[tableNo].DefaultView;
dataView.Sort = sortTableColumn Name;
dataGrid.DataSo urce = dataView;

//incorrect - not the correct cell value of the grid for the TB
numberTB.Text = (string) (dataGrid[dataGrid.Curren tRowIndex, columnNo]);

Steve

Nov 16 '05 #2
//I hope this is the info your looking for
//The NumberTB property VS window under Data->DataBinding->Text says
configMgmtLogDS - StevesConfigMgm tLog.DocumentNu mber
//and nothing else (Tag, etc)

//The InitializeCompo nent() says
this.dGrid.Data Source = this.configMgmt LogDS.StevesCon figMgmtLog;
this.numberTB.D ataBindings.Add (new System.Windows. Forms.Binding(" Text",
this.configMgmt LogDS, "StevesConfigMg mtLog.DocumentN umber"));

ConfigMgmtLog_L oad() //ConfigMgmtLog is Access dB
{
//opens the database and fills the DS
LoadDataFromDat aBase();

//load the DataTable for the dbaseTableName, 1 per class
LoadDataTable() ;

//sets the sort and binds the DataView to the DataGrid
setGridSort(con figMgmtLogDS, dGrid, gridSortedByCol umn, numberZero);

setGridTableSty le(dGrid, configMgmtLogDS );

//change column names and width
setGridNamesAnd Width(dGrid);

bindDataBase_To _DataGrid(); //binding at startup (no event)

OrganizeDataGri dColums(dGrid); //
}

bindDataBase_To _DataGrid()
{
int idColumnNo = getDataSetColum nNumber(configM gmtLogDS, dbaseTableName,
"ID");

if (dGrid.CurrentR owIndex >= 0)
{
int contentsDataGri dID = (int) (dGrid[dGrid.CurrentRo wIndex, idColumnNo]);
int matchingDataSet RowNumber =
findMatchingDat aGridDataSetRow Number(contents DataGridID);

if (matchingDataSe tRowNumber >= 0)
this.BindingCon text[configMgmtLogDS , dbaseTableName].Position =
matchingDataSet RowNumber;
}
}

"Nicholas Paldino [.NET/C# MVP]" wrote:
Steve,

Are you setting up the data binding correctly? Is the data source that
you are connecting the grid to the same as the data source that you are
binding the textboxes to?

Can you show a piece of code that shows the issue?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Steve B." <St****@discuss ions.microsoft. com> wrote in message
news:52******** *************** ***********@mic rosoft.com...
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's
reflect the contents of the grid cells.

Sorting of columns (both thru VS and programmaticall y) work fine except,
when the form/grid first opens up and the grid is immediately sorted the
TB
don't reflect the sorted data of the First row of the grid.

Note: Initially the black grid indicator arrow points to the first row. If
the user choses another row and then sorts the TB's reflect proper data.

//setGridSort(Dat aSet dataSet, DataGrid dataGrid, string
sortTableColumn Name, int tableNo)
DataView dataView = createNewDataVi ew();
dataView = dataSet.Tables[tableNo].DefaultView;
dataView.Sort = sortTableColumn Name;
dataGrid.DataSo urce = dataView;

//incorrect - not the correct cell value of the grid for the TB
numberTB.Text = (string) (dataGrid[dataGrid.Curren tRowIndex, columnNo]);

Steve


Nov 16 '05 #3
Steve,

It looks like you are using two separate data sources. The grid is
binding to this.configMgmt LogDS.StevesCon figMgmtLog, while the textbox is
binding to this.configMgmt LogDS. Even though the binding says to get member
"StevesConfigMg mtLog.DocumentN umber", which effectively gets the data table
StevesConfigMgm tLog, they are two separate data sources.

You should either change the grid data source to be this.configMgmt LogDS
and set the data member to "StevesConfigMg mtLog", or switch the data source
of the TextBox binding to this.configMgmt LogDS.StevesCon figMgmtLog, and set
the member to DocumentNumber.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Steve B." <St****@discuss ions.microsoft. com> wrote in message
news:1C******** *************** ***********@mic rosoft.com...
//I hope this is the info your looking for
//The NumberTB property VS window under Data->DataBinding->Text says
configMgmtLogDS - StevesConfigMgm tLog.DocumentNu mber
//and nothing else (Tag, etc)

//The InitializeCompo nent() says
this.dGrid.Data Source = this.configMgmt LogDS.StevesCon figMgmtLog;
this.numberTB.D ataBindings.Add (new System.Windows. Forms.Binding(" Text",
this.configMgmt LogDS, "StevesConfigMg mtLog.DocumentN umber"));

ConfigMgmtLog_L oad() //ConfigMgmtLog is Access dB
{
//opens the database and fills the DS
LoadDataFromDat aBase();

//load the DataTable for the dbaseTableName, 1 per class
LoadDataTable() ;

//sets the sort and binds the DataView to the DataGrid
setGridSort(con figMgmtLogDS, dGrid, gridSortedByCol umn, numberZero);

setGridTableSty le(dGrid, configMgmtLogDS );

//change column names and width
setGridNamesAnd Width(dGrid);

bindDataBase_To _DataGrid(); //binding at startup (no event)

OrganizeDataGri dColums(dGrid); //
}

bindDataBase_To _DataGrid()
{
int idColumnNo = getDataSetColum nNumber(configM gmtLogDS, dbaseTableName,
"ID");

if (dGrid.CurrentR owIndex >= 0)
{
int contentsDataGri dID = (int) (dGrid[dGrid.CurrentRo wIndex,
idColumnNo]);
int matchingDataSet RowNumber =
findMatchingDat aGridDataSetRow Number(contents DataGridID);

if (matchingDataSe tRowNumber >= 0)
this.BindingCon text[configMgmtLogDS , dbaseTableName].Position =
matchingDataSet RowNumber;
}
}

"Nicholas Paldino [.NET/C# MVP]" wrote:
Steve,

Are you setting up the data binding correctly? Is the data source
that
you are connecting the grid to the same as the data source that you are
binding the textboxes to?

Can you show a piece of code that shows the issue?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Steve B." <St****@discuss ions.microsoft. com> wrote in message
news:52******** *************** ***********@mic rosoft.com...
>I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's
> reflect the contents of the grid cells.
>
> Sorting of columns (both thru VS and programmaticall y) work fine
> except,
> when the form/grid first opens up and the grid is immediately sorted
> the
> TB
> don't reflect the sorted data of the First row of the grid.
>
> Note: Initially the black grid indicator arrow points to the first row.
> If
> the user choses another row and then sorts the TB's reflect proper
> data.
>
> //setGridSort(Dat aSet dataSet, DataGrid dataGrid, string
> sortTableColumn Name, int tableNo)
> DataView dataView = createNewDataVi ew();
> dataView = dataSet.Tables[tableNo].DefaultView;
> dataView.Sort = sortTableColumn Name;
> dataGrid.DataSo urce = dataView;
>
> //incorrect - not the correct cell value of the grid for the TB
> numberTB.Text = (string) (dataGrid[dataGrid.Curren tRowIndex,
> columnNo]);
>
> Steve
>


Nov 16 '05 #4
//I really wish I had success BUT, currently:

//See last thread entry for method content
setGridSort(Dat aSet dataSet, DataGrid dataGrid,
string sortTableColumn Name, int tableNo);

//current dGrid Bindings
this.dGrid.Data Member = "StevesConfigMg mtLog";
this.dGrid.Data Source = this.configMgmt LogDS;

//current TextBox Binding
this.numberTB.D ataBindings.Add (new System.Windows. Forms.Binding(" Text",
this.configMgmt LogDS, "StevesConfigMg mtLog.DocumentN umber"));

//AFTER GRID SORT
//and not moving the black grid indicator arrowhead

//incorrent - displays first entry in the DataSet
numberTB.Text = (string) configMgmtLogDS .Tables[dbaseTableName].Rows[0][5];

//incorrent - displays entry that shown in grid before grid sort
numberTB.Text = (string) dGrid[0, 5];

Steve

"Nicholas Paldino [.NET/C# MVP]" wrote:
Steve,

It looks like you are using two separate data sources. The grid is
binding to this.configMgmt LogDS.StevesCon figMgmtLog, while the textbox is
binding to this.configMgmt LogDS. Even though the binding says to get member
"StevesConfigMg mtLog.DocumentN umber", which effectively gets the data table
StevesConfigMgm tLog, they are two separate data sources.

You should either change the grid data source to be this.configMgmt LogDS
and set the data member to "StevesConfigMg mtLog", or switch the data source
of the TextBox binding to this.configMgmt LogDS.StevesCon figMgmtLog, and set
the member to DocumentNumber.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Steve B." <St****@discuss ions.microsoft. com> wrote in message
news:1C******** *************** ***********@mic rosoft.com...
//I hope this is the info your looking for
//The NumberTB property VS window under Data->DataBinding->Text says
configMgmtLogDS - StevesConfigMgm tLog.DocumentNu mber
//and nothing else (Tag, etc)

//The InitializeCompo nent() says
this.dGrid.Data Source = this.configMgmt LogDS.StevesCon figMgmtLog;
this.numberTB.D ataBindings.Add (new System.Windows. Forms.Binding(" Text",
this.configMgmt LogDS, "StevesConfigMg mtLog.DocumentN umber"));

ConfigMgmtLog_L oad() //ConfigMgmtLog is Access dB
{
//opens the database and fills the DS
LoadDataFromDat aBase();

//load the DataTable for the dbaseTableName, 1 per class
LoadDataTable() ;

//sets the sort and binds the DataView to the DataGrid
setGridSort(con figMgmtLogDS, dGrid, gridSortedByCol umn, numberZero);

setGridTableSty le(dGrid, configMgmtLogDS );

//change column names and width
setGridNamesAnd Width(dGrid);

bindDataBase_To _DataGrid(); //binding at startup (no event)

OrganizeDataGri dColums(dGrid); //
}

bindDataBase_To _DataGrid()
{
int idColumnNo = getDataSetColum nNumber(configM gmtLogDS, dbaseTableName,
"ID");

if (dGrid.CurrentR owIndex >= 0)
{
int contentsDataGri dID = (int) (dGrid[dGrid.CurrentRo wIndex,
idColumnNo]);
int matchingDataSet RowNumber =
findMatchingDat aGridDataSetRow Number(contents DataGridID);

if (matchingDataSe tRowNumber >= 0)
this.BindingCon text[configMgmtLogDS , dbaseTableName].Position =
matchingDataSet RowNumber;
}
}

"Nicholas Paldino [.NET/C# MVP]" wrote:
Steve,

Are you setting up the data binding correctly? Is the data source
that
you are connecting the grid to the same as the data source that you are
binding the textboxes to?

Can you show a piece of code that shows the issue?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Steve B." <St****@discuss ions.microsoft. com> wrote in message
news:52******** *************** ***********@mic rosoft.com...
>I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's
> reflect the contents of the grid cells.
>
> Sorting of columns (both thru VS and programmaticall y) work fine
> except,
> when the form/grid first opens up and the grid is immediately sorted
> the
> TB
> don't reflect the sorted data of the First row of the grid.
>
> Note: Initially the black grid indicator arrow points to the first row.
> If
> the user choses another row and then sorts the TB's reflect proper
> data.
>
> //setGridSort(Dat aSet dataSet, DataGrid dataGrid, string
> sortTableColumn Name, int tableNo)
> DataView dataView = createNewDataVi ew();
> dataView = dataSet.Tables[tableNo].DefaultView;
> dataView.Sort = sortTableColumn Name;
> dataGrid.DataSo urce = dataView;
>
> //incorrect - not the correct cell value of the grid for the TB
> numberTB.Text = (string) (dataGrid[dataGrid.Curren tRowIndex,
> columnNo]);
>
> Steve
>


Nov 16 '05 #5

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

Similar topics

3
539
by: sam | last post by:
Hello Group, Havent had luck posting it to microsoft.public.dotnet.framework.aspnet.datagridcontrol group. Excuse me for the cross posting. I have a datagrid which needs to be split into multiple pages when printing along with headers on every page. I came up with this routine below which adds 2 rows - one with datagrid headers and the other is also a headers which consists other related information. The 2 rows(headers) needs to be...
2
9915
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell (multi-select without modifier keys). I got that working fine, but I also wanted to keep rows selected after a sort, which I do by storing the row's id in an arraylist. The idea was to do the sort and then go back and re-select the rows with that...
1
2054
by: Sargas Atum | last post by:
Hi all, 1. I have a problem with cell selection in a table in a DataGrid. I dont want that anybody writes in the cells. That was not a problem I changed them to "read only", but if I am going to scroll the table up and down or from right to the left the content of the active cell will be selected as if for copy/paste. How can I deactivate such a behaviour?
0
1515
by: elime | last post by:
Hi all I have a strange behaving on some PC with my DataGrid. It only occurs on some PC, on others it works perfectly fine. ->(same ..net version installed) it's very confusing. starting position: I click with the mouse into a cell of the DataGrid, the cell gets active (gray) and marks the cell-content.
2
3173
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchTopQuestionsAboutASPNETDataGridServerControl.asp, Selecting Rows by Clicking Anywhere). Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, _ ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
2
2210
by: Joe Au | last post by:
I follow the Walkthrough documented on Visual Studio to create an editable data grid but it does not work on getting the value of the textbox in the data grid. The code is copied here. I mark "*****" at which the categoryName always get the past value no matter what it has been changed. How do I fix it? Thanks. Joe. Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As...
10
1417
by: Kejpa | last post by:
Hi, I've just started using the datagrid and I have a few questions on it... 1. How do you autosize the columns to fit the content programmatically? When you double click between two columns you'll get the left one autosized to it's content, I want to do that when I load the grid with data. 2. How do you sort the grid using a command button? When you click the column header you will get the grid sorted in ascending/descending order, my...
10
4939
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than the column order of the datatable). I also allow the user to click on a column header to sort the datagrid by that column. I need to identify the row and column in the datatable when the user clicks on a cell in the datagrid. Using the...
2
2843
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box appears in the cell, but allways the first item in the dropdown box is shown not the current cell value? How do I make the current value in the cell automaticaly be selected in the dropdown box.
0
7979
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7894
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8281
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3893
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2409
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1497
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.