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

Welcome to IWETHEY!

New Re: More C# / Windows Forms questions
If I use that button to call another form, and that other form has a datagrid that gets populated with a sql query, how to I get that information back into the field on the primary form?

Hell, how do I even CHOOSE the data?
I can click on a row.
Hmm, I assume I can create a button that asks the grid what is currently highlit.

On an ASP.NET form grid you can stick buttons into the grid, which is probably the simplest. If you do that, when the button is clicked, the event args object will indicate which rows button was clicked.

If you want to put a button under the grid, then you will need to look for a selected row or currently selected property for the grid object.

And then I have to communicate that back to the original text field.

I assume it is a scoping issue.

There are a lot of ways of doing that. The cleanest is probably to pass a reference to the object you want to update, and keep that in a form level variable. Either directly as part of the new form call or as a form level function that you call right after creating the form. That way your subform is not tied to the form it pops up over, you can use the same subform over multiple forms and updating different objects.

If the subform is specific to the main form, then putting a hard coded reference in may be acceptable. Something like App.Forms["FormID"].FindControl["TextBox"]. But I don't know .NET forms well enough to be sure about how to structure that of the top of my head.

Jay
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)

Remember... save the wax!
64 ms