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

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 programmatically) 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(DataSet dataSet, DataGrid dataGrid, string
sortTableColumnName, int tableNo)
DataView dataView = createNewDataView();
dataView = dataSet.Tables[tableNo].DefaultView;
dataView.Sort = sortTableColumnName;
dataGrid.DataSource = dataView;

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

Steve

Nov 16 '05 #1
4 2811
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.com

"Steve B." <St****@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.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 programmatically) 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(DataSet dataSet, DataGrid dataGrid, string
sortTableColumnName, int tableNo)
DataView dataView = createNewDataView();
dataView = dataSet.Tables[tableNo].DefaultView;
dataView.Sort = sortTableColumnName;
dataGrid.DataSource = dataView;

//incorrect - not the correct cell value of the grid for the TB
numberTB.Text = (string) (dataGrid[dataGrid.CurrentRowIndex, 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 - StevesConfigMgmtLog.DocumentNumber
//and nothing else (Tag, etc)

//The InitializeComponent() says
this.dGrid.DataSource = this.configMgmtLogDS.StevesConfigMgmtLog;
this.numberTB.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.configMgmtLogDS, "StevesConfigMgmtLog.DocumentNumber"));

ConfigMgmtLog_Load() //ConfigMgmtLog is Access dB
{
//opens the database and fills the DS
LoadDataFromDataBase();

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

//sets the sort and binds the DataView to the DataGrid
setGridSort(configMgmtLogDS, dGrid, gridSortedByColumn, numberZero);

setGridTableStyle(dGrid, configMgmtLogDS);

//change column names and width
setGridNamesAndWidth(dGrid);

bindDataBase_To_DataGrid(); //binding at startup (no event)

OrganizeDataGridColums(dGrid); //
}

bindDataBase_To_DataGrid()
{
int idColumnNo = getDataSetColumnNumber(configMgmtLogDS, dbaseTableName,
"ID");

if (dGrid.CurrentRowIndex >= 0)
{
int contentsDataGridID = (int) (dGrid[dGrid.CurrentRowIndex, idColumnNo]);
int matchingDataSetRowNumber =
findMatchingDataGridDataSetRowNumber(contentsDataG ridID);

if (matchingDataSetRowNumber >= 0)
this.BindingContext[configMgmtLogDS, dbaseTableName].Position =
matchingDataSetRowNumber;
}
}

"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.com

"Steve B." <St****@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.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 programmatically) 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(DataSet dataSet, DataGrid dataGrid, string
sortTableColumnName, int tableNo)
DataView dataView = createNewDataView();
dataView = dataSet.Tables[tableNo].DefaultView;
dataView.Sort = sortTableColumnName;
dataGrid.DataSource = dataView;

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

Steve


Nov 16 '05 #3
Steve,

It looks like you are using two separate data sources. The grid is
binding to this.configMgmtLogDS.StevesConfigMgmtLog, while the textbox is
binding to this.configMgmtLogDS. Even though the binding says to get member
"StevesConfigMgmtLog.DocumentNumber", which effectively gets the data table
StevesConfigMgmtLog, they are two separate data sources.

You should either change the grid data source to be this.configMgmtLogDS
and set the data member to "StevesConfigMgmtLog", or switch the data source
of the TextBox binding to this.configMgmtLogDS.StevesConfigMgmtLog, and set
the member to DocumentNumber.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steve B." <St****@discussions.microsoft.com> wrote in message
news:1C**********************************@microsof t.com...
//I hope this is the info your looking for
//The NumberTB property VS window under Data->DataBinding->Text says
configMgmtLogDS - StevesConfigMgmtLog.DocumentNumber
//and nothing else (Tag, etc)

//The InitializeComponent() says
this.dGrid.DataSource = this.configMgmtLogDS.StevesConfigMgmtLog;
this.numberTB.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.configMgmtLogDS, "StevesConfigMgmtLog.DocumentNumber"));

ConfigMgmtLog_Load() //ConfigMgmtLog is Access dB
{
//opens the database and fills the DS
LoadDataFromDataBase();

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

//sets the sort and binds the DataView to the DataGrid
setGridSort(configMgmtLogDS, dGrid, gridSortedByColumn, numberZero);

setGridTableStyle(dGrid, configMgmtLogDS);

//change column names and width
setGridNamesAndWidth(dGrid);

bindDataBase_To_DataGrid(); //binding at startup (no event)

OrganizeDataGridColums(dGrid); //
}

bindDataBase_To_DataGrid()
{
int idColumnNo = getDataSetColumnNumber(configMgmtLogDS, dbaseTableName,
"ID");

if (dGrid.CurrentRowIndex >= 0)
{
int contentsDataGridID = (int) (dGrid[dGrid.CurrentRowIndex,
idColumnNo]);
int matchingDataSetRowNumber =
findMatchingDataGridDataSetRowNumber(contentsDataG ridID);

if (matchingDataSetRowNumber >= 0)
this.BindingContext[configMgmtLogDS, dbaseTableName].Position =
matchingDataSetRowNumber;
}
}

"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.com

"Steve B." <St****@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.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 programmatically) 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(DataSet dataSet, DataGrid dataGrid, string
> sortTableColumnName, int tableNo)
> DataView dataView = createNewDataView();
> dataView = dataSet.Tables[tableNo].DefaultView;
> dataView.Sort = sortTableColumnName;
> dataGrid.DataSource = dataView;
>
> //incorrect - not the correct cell value of the grid for the TB
> numberTB.Text = (string) (dataGrid[dataGrid.CurrentRowIndex,
> columnNo]);
>
> Steve
>


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

//See last thread entry for method content
setGridSort(DataSet dataSet, DataGrid dataGrid,
string sortTableColumnName, int tableNo);

//current dGrid Bindings
this.dGrid.DataMember = "StevesConfigMgmtLog";
this.dGrid.DataSource = this.configMgmtLogDS;

//current TextBox Binding
this.numberTB.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.configMgmtLogDS, "StevesConfigMgmtLog.DocumentNumber"));

//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.configMgmtLogDS.StevesConfigMgmtLog, while the textbox is
binding to this.configMgmtLogDS. Even though the binding says to get member
"StevesConfigMgmtLog.DocumentNumber", which effectively gets the data table
StevesConfigMgmtLog, they are two separate data sources.

You should either change the grid data source to be this.configMgmtLogDS
and set the data member to "StevesConfigMgmtLog", or switch the data source
of the TextBox binding to this.configMgmtLogDS.StevesConfigMgmtLog, and set
the member to DocumentNumber.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steve B." <St****@discussions.microsoft.com> wrote in message
news:1C**********************************@microsof t.com...
//I hope this is the info your looking for
//The NumberTB property VS window under Data->DataBinding->Text says
configMgmtLogDS - StevesConfigMgmtLog.DocumentNumber
//and nothing else (Tag, etc)

//The InitializeComponent() says
this.dGrid.DataSource = this.configMgmtLogDS.StevesConfigMgmtLog;
this.numberTB.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.configMgmtLogDS, "StevesConfigMgmtLog.DocumentNumber"));

ConfigMgmtLog_Load() //ConfigMgmtLog is Access dB
{
//opens the database and fills the DS
LoadDataFromDataBase();

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

//sets the sort and binds the DataView to the DataGrid
setGridSort(configMgmtLogDS, dGrid, gridSortedByColumn, numberZero);

setGridTableStyle(dGrid, configMgmtLogDS);

//change column names and width
setGridNamesAndWidth(dGrid);

bindDataBase_To_DataGrid(); //binding at startup (no event)

OrganizeDataGridColums(dGrid); //
}

bindDataBase_To_DataGrid()
{
int idColumnNo = getDataSetColumnNumber(configMgmtLogDS, dbaseTableName,
"ID");

if (dGrid.CurrentRowIndex >= 0)
{
int contentsDataGridID = (int) (dGrid[dGrid.CurrentRowIndex,
idColumnNo]);
int matchingDataSetRowNumber =
findMatchingDataGridDataSetRowNumber(contentsDataG ridID);

if (matchingDataSetRowNumber >= 0)
this.BindingContext[configMgmtLogDS, dbaseTableName].Position =
matchingDataSetRowNumber;
}
}

"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.com

"Steve B." <St****@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.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 programmatically) 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(DataSet dataSet, DataGrid dataGrid, string
> sortTableColumnName, int tableNo)
> DataView dataView = createNewDataView();
> dataView = dataSet.Tables[tableNo].DefaultView;
> dataView.Sort = sortTableColumnName;
> dataGrid.DataSource = dataView;
>
> //incorrect - not the correct cell value of the grid for the TB
> numberTB.Text = (string) (dataGrid[dataGrid.CurrentRowIndex,
> columnNo]);
>
> Steve
>


Nov 16 '05 #5

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

Similar topics

3
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...
2
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...
1
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...
0
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...
2
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...
2
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...
10
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...
10
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...
2
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...
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...
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...
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.