6 Replies - 581 Views - Last Post: 25 January 2013 - 02:32 PM Rate Topic: -----

#1 rdchaitanya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-September 12

Datagrid .net 1.1 Trying to store datagrid cell content in a string...

Posted 24 January 2013 - 11:57 AM

I am using .net 1.1. I am displaying the content of a table in a datagrid. My task is -> when i select any row in the datagrid it should load the select row content in the form.



public void DispalyCustomer(string CustomerName)
		{
			string DbConn = ConfigurationSettings.AppSettings["DbConn"];
			SqlConnection objConnection = new SqlConnection(DbConn);
			objConnection.Open();
			//Fire the command object

			SqlCommand objCommand = new SqlCommand("select * from Customertable where Customername = '"+ CustomerName +"'",objConnection);
			DataSet objDataset = new DataSet();
			SqlDataAdapter objAdapter = new SqlDataAdapter(objCommand);
			objAdapter.Fill(objDataset);

			//Display selected content on the screen
			string strcustomername = objDataset.Tables[0].Rows[0][0].ToString();
			string strcoyntrtname = objDataset.Tables[0].Rows[0][1].ToString();
			string strgender = objDataset.Tables[0].Rows[0][2].ToString();
			string strhobbies = objDataset.Tables[0].Rows[0][3].ToString();
			bool strstatus = Convert.ToBoolean(objDataset.Tables[0].Rows[0][4]);
			
			//Close the connection
			objConnection.Close();
		}

		private void dtgcustomer_Click(object sender, System.EventArgs e)
		{
			string strSelectedCustomer = dtgcustomer.CurrentCell.RowNumber.ToString();
			DispalyCustomer(strSelectedCustomer);
		}




i am trying to store the datagrid cell data into the string strSelectedCustomer and pass it to displaycustomer.

Is This A Good Question/Topic? 0
  • +

Replies To: Datagrid .net 1.1 Trying to store datagrid cell content in a string...

#2 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1182
  • View blog
  • Posts: 1,677
  • Joined: 24-August 11

Re: Datagrid .net 1.1 Trying to store datagrid cell content in a string...

Posted 24 January 2013 - 01:42 PM

What's the problem? What is your code doing that it shouldn't do, or not doing that it should do?
Was This Post Helpful? 0
  • +
  • -

#3 rdchaitanya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-September 12

Re: Datagrid .net 1.1 Trying to store datagrid cell content in a string...

Posted 24 January 2013 - 02:26 PM

i am a fresher. I don't know how to store a datagrid cell content in a variable and the .net framework in my office is .net 1.1.

private void dtgcustomer_Click(object sender, System.EventArgs e)  

    {  

           string strSelectedCustomer = dtgcustomer.CurrentCell.RowNumber.ToString();  

            DispalyCustomer(strSelectedCustomer);  

       } 




My question is there any event that fires when i select a row in the datagrid in .net 1.1 (I found a event in .net 4.0 but that is not available in .net 1.1)

i want to capture the selected row's first column and store it in a string....

How do i do it??
Was This Post Helpful? 0
  • +
  • -

#4 rdchaitanya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-September 12

Re: Datagrid .net 1.1 Trying to store datagrid cell content in a string...

Posted 24 January 2013 - 02:38 PM

Posted Image


This is how the windows application looks
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,467
  • Joined: 05-May 12

Re: Datagrid .net 1.1 Trying to store datagrid cell content in a string...

Posted 24 January 2013 - 07:43 PM

You didn't look closely enough: CurrentCellChanged and Click events have been present in the DataGrid since .NET 1.1:
CurrentCellChanged: http://msdn.microsof...d(v=vs.71).aspx
Click: http://msdn.microsof...k(v=vs.71).aspx
Was This Post Helpful? 1
  • +
  • -

#6 rdchaitanya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 26-September 12

Re: Datagrid .net 1.1 Trying to store datagrid cell content in a string...

Posted 25 January 2013 - 11:50 AM

i am using CurrentCellChanged event but i am not able to store the value of the selected cell in a string variable..

I am not sure how the code looks like...
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,467
  • Joined: 05-May 12

Re: Datagrid .net 1.1 Trying to store datagrid cell content in a string...

Posted 25 January 2013 - 02:32 PM

I highly recommend learning how to read MSDN recommendation. The CurrentCell property is a DataGridCell type which contains the row and column number. Using the row number and cell number, you can then index back into the DataGrid.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1