IWETHEY v. 0.3.0 | TODO
1,095 registered users | 3 active users | 1 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Getting the data
Note: You mention ASP.NET - I'm doing local C# app. The docs intermix the 2 all the time though. Bleck.

Ok, so, I've got the button.
The fill grid looks like this:
\nprivate void fill_grid()            \n{                  \n   string strConn, strSQL;                  \n   strConn = "Provider=SQLOLEDB;" +                        \n    "data source=DB;" +\n    "Integrated Security=SSPI;" +\n    "Initial Catalog=CAT";                                          \n\n    strSQL = "select item_number, description, client, company, division from t_item_master";\n\tOleDbDataAdapter da = new OleDbDataAdapter(strSQL, strConn);                  \n\tDataSet ds = new DataSet();                  \n\tda.Fill(ds, "t_item_master");                  \n\tFormCodeGrid.DataMember = "t_item_master";                  \n\tFormCodeGrid.DataSource=ds;            \n}\n\n

The button even handler looks like this:
\nprivate void btnSelect_Click(object sender, System.EventArgs e)\n {\n    int row = FormCodeGrid.CurrentRowIndex;\n    MessageBox.Show("Selected: " +  row);\t\t\t\n}\n


How to I actually the the DATA based on knowing the index?

New Re: Getting the data
Note: You mention ASP.NET - I'm doing local C# app. The docs intermix the 2 all the time though. Bleck.

I've studied the WinForms and application stuff a bit, but all the real work I've done is with ASP.NET. So that is the only part I can remember, and I'm on vacation right now so I can't be bothered to look it up. Microsoft has gotten the underlying objects very nearly the same though, even when it forces them to be stupid.

Something like this should work.

int row = FormCodeGrid.CurrentRowIndex;
string TheText = FormCodeGrid.Rows[row].Cells[TheColumnWeCareAbout].Text;

Depending on the type of Grid you may be able to do this also.

string TheText = FormCodeGrid.SelectedRow.Cells[TheColumnWeCareAbout].Text;

Jay
New Neither works
'System.Windows.Forms.DataGrid' does not contain a definition for 'Rows'

Grrr.

I'll look further.

Thanks
New Getting closer
MessageBox.Show ("Col is " + FormCodeGrid.CurrentCell.ColumnNumber
+ ", Row is " + FormCodeGrid.CurrentCell.RowNumber
+ ", Value is " + FormCodeGrid[FormCodeGrid.CurrentCell] );

So now how do I pick a particular field in the table,
since only the 1st column has the data I want.

Or, barring that, disable picking of any other cell than the 1st one.
New Got it
Grid items are addressed by cell.
I create the cell based on row / column attributes.
I know my field is first, so I pull the one.

Thanks
New Re: Getting closer
MessageBox.Show ("Col is " + FormCodeGrid.CurrentCell.ColumnNumber
+ ", Row is " + FormCodeGrid.CurrentCell.RowNumber
+ ", Value is " + FormCodeGrid[FormCodeGrid.CurrentCell] );

So now how do I pick a particular field in the table,
since only the 1st column has the data I want.

Hm, must be some big differences between the ASP.NET grids and the WinForms grid. The ASP grid doesn't have a concept of selected cell, only selected row.

As for limiting them to the right column, don't bother. Just pull the RowNumber from the current cell and then use that to get the cell you care about. That way it doesn't matter where in the row they click. Though you should somehow mark which columns value is important.

Actually, that might be difficult if the application grid doesn't have a Rows property. But I find it hard to believe that it doesn't have something that does the same thing.

jay
New Yup - see other post
     More C# / Windows Forms questions - (crazy) - (10)
         Re: More C# / Windows Forms questions - (JayMehaffey) - (7)
             Getting the data - (crazy) - (6)
                 Re: Getting the data - (JayMehaffey) - (1)
                     Neither works - (crazy)
                 Getting closer - (crazy) - (3)
                     Got it - (crazy)
                     Re: Getting closer - (JayMehaffey) - (1)
                         Yup - see other post -NT - (crazy)
         A couple of ways to do it... - (ChrisR) - (1)
             Got it - (crazy)

Pre-Pass Follow in-cab signals.
70 ms