Click here to Skip to main content
15,917,321 members
Home / Discussions / C#
   

C#

 
AnswerRe: Which is the best way to shutdown, reboot, or logoff from the system in C# (.NEt 4.0)? Pin
Luc Pattyn14-Jan-11 0:33
sitebuilderLuc Pattyn14-Jan-11 0:33 
AnswerRe: Which is the best way to shutdown, reboot, or logoff from the system in C# (.NEt 4.0)? Pin
Ravi Sant14-Jan-11 1:50
Ravi Sant14-Jan-11 1:50 
GeneralRe: Which is the best way to shutdown, reboot, or logoff from the system in C# (.NEt 4.0)? Pin
Dave Kreskowiak14-Jan-11 4:01
mveDave Kreskowiak14-Jan-11 4:01 
GeneralRe: Which is the best way to shutdown, reboot, or logoff from the system in C# (.NEt 4.0)? Pin
jschell14-Jan-11 9:58
jschell14-Jan-11 9:58 
AnswerRe: Which is the best way to shutdown, reboot, or logoff from the system in C# (.NEt 4.0)? Pin
Dave Kreskowiak14-Jan-11 4:05
mveDave Kreskowiak14-Jan-11 4:05 
QuestionGetting network drives names issue Pin
Priya Prk13-Jan-11 21:34
Priya Prk13-Jan-11 21:34 
AnswerRe: Getting network drives names issue Pin
RaviRanjanKr13-Jan-11 22:24
professionalRaviRanjanKr13-Jan-11 22:24 
GeneralRe: Getting network drives names issue Pin
OriginalGriff13-Jan-11 22:41
mveOriginalGriff13-Jan-11 22:41 
GeneralRe: Getting network drives names issue Pin
Priya Prk13-Jan-11 23:07
Priya Prk13-Jan-11 23:07 
AnswerRe: Getting network drives names issue Pin
Goutam Patra13-Jan-11 23:04
professionalGoutam Patra13-Jan-11 23:04 
GeneralRe: Getting network drives names issue Pin
Priya Prk13-Jan-11 23:09
Priya Prk13-Jan-11 23:09 
GeneralRe: Getting network drives names issue Pin
RaviRanjanKr13-Jan-11 23:14
professionalRaviRanjanKr13-Jan-11 23:14 
GeneralRe: Getting network drives names issue Pin
Goutam Patra13-Jan-11 23:25
professionalGoutam Patra13-Jan-11 23:25 
AnswerRe: Getting network drives names issue Pin
Pete O'Hanlon13-Jan-11 23:21
mvePete O'Hanlon13-Jan-11 23:21 
GeneralRe: Getting network drives names issue Pin
Priya Prk13-Jan-11 23:32
Priya Prk13-Jan-11 23:32 
AnswerRe: Getting network drives names issue Pin
Luc Pattyn14-Jan-11 1:41
sitebuilderLuc Pattyn14-Jan-11 1:41 
GeneralRe: Getting network drives names issue Pin
Priya Prk14-Jan-11 2:01
Priya Prk14-Jan-11 2:01 
GeneralRe: Getting network drives names issue Pin
Dave Kreskowiak14-Jan-11 4:00
mveDave Kreskowiak14-Jan-11 4:00 
AnswerRe: Getting network drives names issue Pin
jschell14-Jan-11 10:04
jschell14-Jan-11 10:04 
QuestionTreeView SelectedNode[0] Pin
S078413-Jan-11 21:14
S078413-Jan-11 21:14 
AnswerRe: TreeView SelectedNode[0] Pin
Mycroft Holmes13-Jan-11 21:27
professionalMycroft Holmes13-Jan-11 21:27 
AnswerRe: TreeView SelectedNode[0] Pin
Richard MacCutchan13-Jan-11 22:08
mveRichard MacCutchan13-Jan-11 22:08 
AnswerRe: TreeView SelectedNode[0] Pin
RaviRanjanKr16-Jan-11 2:28
professionalRaviRanjanKr16-Jan-11 2:28 
GeneralRe: TreeView SelectedNode[0] Pin
S078416-Jan-11 19:53
S078416-Jan-11 19:53 
QuestionC# How to get row value of DataGridView Pin
LAPEC13-Jan-11 12:46
LAPEC13-Jan-11 12:46 
Hello Everyone

Im generating two columns of dataGridView from database on click event button. The first column is FoodName, second column is FoodType.

On my dataGridView I have set it a click event so the user can enter a number on particular cell of the third column like so...

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            // make sure that the click was in the right column
            if (e.ColumnIndex == 2)
            {
                // Value is given in case the cell is empty
                string cellContent = "0";
                if (this.dataGridView1[e.ColumnIndex, e.RowIndex].Value != null)
                {
                    cellContent = this.dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
                }
                using (InputBox ib = new InputBox("Enter new stock amount:", this.dataGridView1[0, e.RowIndex].Value.ToString(), cellContent))
                {
                    if (ib.ShowDialog() == DialogResult.OK)
                    {
                        this.dataGridView1[e.ColumnIndex, e.RowIndex].Value = ib.Result;
                        cellContent = ib.Result;
                       this.dataGridView1.Controls.Find("btn" + cellValue, true); "THIS IS THE LINE WHERE I WANT TO GET THAT cellFoodTypeValue...
                        
                    }
                }
            }
        } 


How can I get the FoodType value from that row?

Here is the code of my click event button...

(Hence: ColFoodQtyStock and ColFoodStatus are template columns generated at run-time)

private DataGridViewTextBoxColumn ColFoodQtyStock = new DataGridViewTextBoxColumn();
        private DataGridViewTextBoxColumn ColFoodStatus = new DataGridViewTextBoxColumn();

        private void cmdStarters_Click(object sender, EventArgs e)
        {
            OleDbConnectionStringBuilder connBuilder = new OleDbConnectionStringBuilder();
            connBuilder.DataSource = @"C:\Users\AP_AE\Desktop\DTPOS_APP\DataBase\DtposMenu.accdb";
            connBuilder.Provider = "Microsoft.ACE.OLEDB.12.0";
            connBuilder.Add("Jet OLEDB:Engine Type", "5");

            // Food SQL Query
            string foodTypeSql = @"SELECT FoodName, FoodType FROM Food WHERE FoodType = @foodType";
            using (OleDbConnection conn = new OleDbConnection(connBuilder.ConnectionString))
            {
                dataGridView1.Columns.Clear();
                dataGridView1.RowTemplate.Height = 60;
                //====================================\\
                dataGridView1.Visible = true;
                dataGridView2.Visible = false;
                try
                {
                    OleDbCommand foodsCommand = new OleDbCommand(foodTypeSql, conn);
                    OleDbParameter foodType = foodsCommand.Parameters.Add("@foodType", OleDbType.VarChar, 15);
                    OleDbDataAdapter foodsDa = new OleDbDataAdapter(foodsCommand);
                    
                    DataSet ds = new DataSet();
                    conn.Open();
                    foodType.Value = "Starter";
                    foodsDa.Fill(ds, "Food_table");

                    //add extra column structures to dataset
                    ds.Tables["Food_table"].Columns.Add(new DataColumn("Quantity In Stock", System.Type.GetType("System.Int32")));
                    ds.Tables["Food_table"].Columns.Add(new DataColumn("Status", System.Type.GetType("System.String")));
                    //loop through all the rows and add the data to the new columns dynamically
                    for (int i = 0; i < ds.Tables["Food_table"].Rows.Count; i++)
                    {
                        ds.Tables["Food_table"].Rows[i]["Quantity In Stock"] = 0;
                        ds.Tables["Food_table"].Rows[i]["Status"] = "<Always On Stock>";
                    }
                    
                    dataGridView1.DataSource = ds;
                    dataGridView1.DataMember = "Food_table";
                    
                    DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle();
                    this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
                    dataGridViewCellStyle1.Font = new Font("Verdana", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                    this.dataGridView1.Columns[0].Width = 420;
                    this.dataGridView1.Columns[1].Width = 180;
                    this.dataGridView1.Columns[2].Width = 300;
                    this.dataGridView1.Columns[3].Width = 308;

                    conn.Close();

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: " + ex);
                }
            }
        }


Any help please would be very greatfull

Thanks in advance

Lapeci

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.