Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all 2535 articles
Browse latest View live

C# DataGridView host a control in the current DataGridViewCell for editing - PROBLEM

$
0
0

Hello

I have DataGridView with DataTable as source

dt = new DataTable();
dt.Columns.Add(new DataColumn("testString", typeof(String)));
dt.Columns.Add(new DataColumn("testDate", typeof(DateTime)));
dataGridView1.DataSource = dt;

For the second column "testDate" i try to use hosted MaskedTextBox for editing

but in any cases i reseive error (e.Exception.Message) "String was not recognized as valid DateTime" even if it is valid date

If i press ESC key if string is valid date value is accepted but still the same cell is focused.

Also if i click first the cell with mouse and edit after that than is ok.

Please for sugestions,

Best regards,

My Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace TestDGV
{
    public partial class Form1 : Form
    {
        DataGridView dataGridView1;
        DataTable dt;

        MaskedTextBox maskedTextBoxForEditing;
        bool IsKeyPressHandled = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // New DataGridView
            dataGridView1 = new DataGridView();
            dataGridView1.Dock = DockStyle.Fill;

            this.Controls.Add(dataGridView1);

            // New DataTable
            dt = new DataTable();
            dt.Columns.Add(new DataColumn("testString", typeof(String)));
            dt.Columns.Add(new DataColumn("testDate", typeof(DateTime)));
            dataGridView1.DataSource = dt;

            // MaskedTextBox
            this.maskedTextBoxForEditing = new MaskedTextBox();
            this.maskedTextBoxForEditing.Mask = "00/00/0000";
            this.maskedTextBoxForEditing.PromptChar = ' ';
            // Hide the MaskedTextBox
            this.maskedTextBoxForEditing.Visible = false;
            // Add the MaskedTextBox to the DataGridView's control collection
            this.dataGridView1.Controls.Add(this.maskedTextBoxForEditing);


            // the current editing cell
            this.dataGridView1.CellBeginEdit +=
                new DataGridViewCellCancelEventHandler(dataGridView1_CellBeginEdit);

            // Handle the CellEndEdit event to hide the MaskedTextBox when
            // editing completes.
            this.dataGridView1.CellEndEdit += new DataGridViewCellEventHandler(dataGridView1_CellEndEdit);

            // Handle the Scroll event to adjust the location of the MaskedTextBox as it is showing
            // when scrolling the DataGridView
            this.dataGridView1.Scroll += new ScrollEventHandler(dataGridView1_Scroll);

            // Handle the EditingControlShowing event to pass the focus to the
            // MaskedTextBox when begin editing with keystrokes
            this.dataGridView1.EditingControlShowing +=
                new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing);

            // Attach the DataError event to the corresponding event handler.
            this.dataGridView1.DataError +=
                new DataGridViewDataErrorEventHandler(dataGridView1_DataError);
        }

        #region For MaskedTextBox

        void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            // If the current cell is on the "MaskColumn", we use the MaskedTextBox control
            // for editing instead of the default TextBox control;
            if (e.ColumnIndex == this.dataGridView1.Columns["testDate"].Index)
            {
                // Calculate the cell bounds of the current cell
                Rectangle rect = this.dataGridView1.GetCellDisplayRectangle(
                    e.ColumnIndex, e.RowIndex, true);
                // Adjust the MaskedTextBox's size and location to fit the cell
                this.maskedTextBoxForEditing.Size = rect.Size;
                this.maskedTextBoxForEditing.Location = rect.Location;

                // Set value for the MaskedTextBox
                if (this.dataGridView1.CurrentCell.Value != null)
                {
                    this.maskedTextBoxForEditing.Text = this.dataGridView1.CurrentCell.Value.ToString();
                }

                // Show the MaskedTextBox
                this.maskedTextBoxForEditing.Visible = true;
            }
        }

        void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            // When finish editing on the "MaskColumn", we replace the cell value with
            // the text typed in the MaskedTextBox, and hide the MaskedTextBox;
            if (e.ColumnIndex == this.dataGridView1.Columns["testDate"].Index)
            {
                this.dataGridView1.CurrentCell.Value = this.maskedTextBoxForEditing.Text;
                // this.dataGridView1.CurrentCell.Value = Convert.ToDateTime(this.maskedTextBoxForEditing.Text);

                this.maskedTextBoxForEditing.Text = "";
                this.maskedTextBoxForEditing.Visible = false;
            }
        }

        void dataGridView1_Scroll(object sender, ScrollEventArgs e)
        {
            if (this.dataGridView1.IsCurrentCellInEditMode == true)
            {
                // Adjust the location for the MaskedTextBox while scrolling
                Rectangle rect = this.dataGridView1.GetCellDisplayRectangle(
                    this.dataGridView1.CurrentCell.ColumnIndex,
                    this.dataGridView1.CurrentCell.RowIndex, true);

                /*
                Console.WriteLine(rect.ToString());
                Console.WriteLine(this.dataGridView1.CurrentCellAddress.ToString());
                Console.WriteLine("");
                */

                if (rect.X <= 0 || rect.Y <= 0)
                {
                    this.maskedTextBoxForEditing.Visible = false;
                }
                else
                {
                    this.maskedTextBoxForEditing.Location = rect.Location;
                }
            }
        }

        void dataGridView1_EditingControlShowing(object sender,
            DataGridViewEditingControlShowingEventArgs e)
        {
            if (!this.IsKeyPressHandled
                && this.dataGridView1.CurrentCell.ColumnIndex ==
                this.dataGridView1.Columns["testDate"].Index)
            {
                TextBox tb = e.Control as TextBox;
                tb.KeyPress += new KeyPressEventHandler(tb_KeyPress);
                this.IsKeyPressHandled = true;
            }
        }

        void tb_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (this.dataGridView1.CurrentCell.ColumnIndex ==
                this.dataGridView1.Columns["testDate"].Index)
            {
                // Prevent the key char to be input in the editing control
                // e.Handled = true;

                // Set focus to the MaskedTextBox for editing.
                this.maskedTextBoxForEditing.SelectionStart = 0;
                this.maskedTextBoxForEditing.Focus();

                this.maskedTextBoxForEditing.SelectionStart = 0;

                // SendKeys.Send(e.KeyChar.ToString());
            }
        }

        void dataGridView1_DataError(object sender,
            DataGridViewDataErrorEventArgs e)
        {
            // If the data source raises an exception when a cell value is
            // commited, display an error message.

            if (e.Exception != null)
            {
                MessageBox.Show("Data error !" + "\n\n" + e.Exception.Message);
            }
        }

        #endregion

    }
}



Make the currentrowdirty = false

$
0
0
Is there  a way to make the currentrowdirty = false

Debra has a question

Change the Border of a Full Selected Row

$
0
0
 Hi All,

I'm trying to do the following:

I have a datagridview with a fullrowselected selection mode, and I would like to change the full row border when selected, I've tried:

Private

Sub DGCAL_CellPainting(ByVal sender AsObject, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DGCAL.CellPainting

If e.RowIndex = DGCAL.CurrentRow.Index Then
  e.Paint(e.CellBounds, DataGridViewPaintParts.Border)
  Using p = New Pen(Color.Black, 4)
     Dim rect As Rectangle = e.CellBounds
     rect.Width -= 2
     rect.Height -= 2
     e.Graphics.DrawRectangle(p, rect)
  EndUsing
  e.Handled = True
EndIf

EndSub

But I get borders in all cells inside the row insted of a single border all over the row, any suggestion would be eternally appreciated.

Thanks in advance


Duplicate Designer.vb file when saving dataset

$
0
0
I'm having the following problem. When I change the dataset in a project Visual Studio generates a duplicate designer.vb I've tried the solution that was suggested in a similar post of deleting the designer files and running the Custom Tool but I end up with 2 designer files again and of course all of the changes in the dataset are saved in the duplicate dataset1.designer.vb file instead of the correct one.
Of course, the project will not build unless you delete the dataset1.designer.vb file.

Any help would be appreciated.

Luis

Luis R. Lebron

ComboBox is not Refreshed

$
0
0

Hello,

I have a combobox in my one form like City name, And I have Master form for that so I defined fill city combo public so i can call it on form close event of that master...

but combobox is not refreshed with new add or delete value...

Here is my code..

string qry = "Select * from City";
        dtcity = cc.GetDataSection(qry, connection);
        cmbCity.DataSource = null;
        cmbCity.DisplayMember = "CityName";
        cmbCity.ValueMember = "CityId";
        cmbCity.DataSource = dtcity ;

I am getting perfect data in datatable but not in combo box....

Any help would be appreciate..

Thank u...

How to bind data grid view from xml database file based on search ?

$
0
0

Hi all,

          I am trying to make Document uploader winforms c# application ,where we can upload important documents by name  and then search it by name so that can open the document and if required can print the document ,i am using xml database file as database so i am getting problem in binding the datagridview based on search from textbox using Like operator as in sql , and i am also getting the problem on how to make link in data gridview to open the document and make link in datagridview to print the document ? Below is my xml file ,please help in this i am stuck from many days ? Below is the xml file .

The document uploaded is kept in the folder named "Doc_Upl".

I am using VS 2010 and not working in MVC framework.

<?xml version="1.0" standalone="yes"?>
<DOCUMENT_UPLOADER>
  <DOCUMENT>
    <OWNER_ID>Rohit Johri</OWNER_ID>
    <DOCUMENT_NAME>xczb</DOCUMENT_NAME>
    <DOCUMENT_URL>1372016_152710images.jpe</DOCUMENT_URL>
  </DOCUMENT>
  <DOCUMENT>
    <OWNER_ID>Rohit Johri</OWNER_ID>
    <DOCUMENT_NAME>xczb</DOCUMENT_NAME>
    <DOCUMENT_URL>1372016_152710images.jpe</DOCUMENT_URL>
  </DOCUMENT>
  <DOCUMENT>
    <OWNER_ID>Rohit Johri</OWNER_ID>
    <DOCUMENT_NAME>zx</DOCUMENT_NAME>
    <DOCUMENT_URL>1372016_153247Student.jpg</DOCUMENT_URL>
  </DOCUMENT>
  <DOCUMENT>
    <OWNER_ID>Rohit Johri</OWNER_ID>
    <DOCUMENT_NAME>asss</DOCUMENT_NAME>
    <DOCUMENT_URL>1372016_153530download.jpe</DOCUMENT_URL>
  </DOCUMENT>

Thanks in advance

Rohit J



How to disable editing in the existing rows in a datagridview and allow the user to add new row to same?

$
0
0

Hello,

I have a datagridview where I should not be able to edit the the existing rows, but i must be able to add new rows to it.

I have set the datagridview.ReadOnly=True (for disabling edit)

Also to allow the user to add new rows, i have set as  datagridview.AllowUserToAddNewRows=True


But the desired effect is not happening. Still I am not able to add new row.

Can anyone help me in solving this problem?

Thanks in advance.

VOID TRANSACTIONS

$
0
0

I have a datagridview with a column name of (INVOICENO, PRODUCTID, QUANTITY, STATUS) and my rows have a value. And when i click the VOID TRANSACTION button then all the rows of my datagridview should be deleted from the datagridview and UPDATE the QUANTITY to my table Product and CHANGE the STATUS to VOID. Please HELP me. Thanks in advance.


Datagridview combobx

$
0
0

I want a datagridview combobox column to have drop down items which I will add, and the text of the combobox should load with the data already saved in the database. Is that possible and how would I do it?



Debra has a question


How to reset DataGridViewAutoFilterTextBoxColumn?

$
0
0
Hi, I'm using DataGridViewAutiFilterTextBoxColumn in several column in a Datagridview. I would like to reset all filters in all columns with one click (A vb command). How can I do this? Thank you beforehand. Best




Mysql to C# data source connection already exists error

$
0
0
  1. "Some updating commands could not be generated automatically. The database returned the following error:
  2. You have a usable connection already

I am trying to connect MySql to Visual Studio 2012 and this is the error that is am encountering. Please provide a solution.

Thank you.

Reading data from an access database

$
0
0

Hi

I am new to C# so please excuse how bad my code is but I have written code to return values based on a search box however at times, the value entered into the search box can apply to several records within an MSAccess DB.

Is there a way where I can scroll through the records that apply to the value in the search box by using a button?

public void LoopThroughRecs(OleDbDataReader Data) { Data.Read(); { FirstName.Text = Data["Initial"].ToString(); LastName.Text = Data["Surname"].ToString(); Address1.Text = Data["Address 1"].ToString(); Address2.Text = Data["Address 2"].ToString(); Address3.Text = Data["Address 3"].ToString(); TownCity.Text = Data["Post Town"].ToString(); PostCode.Text = Data["Post Code"].ToString(); Telephone.Text = Data["Telephone"].ToString(); LstSvcDat.Text = Data["LastService"].ToString(); BoilerMan.Text = Data["Manufacturer"].ToString(); BoilerMod.Text = Data["Model"].ToString(); } Data.Close(); } public void button2_Click(object sender, EventArgs e) { System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(); conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BoilerSvc_be.mdb"; try { conn.Open(); OleDbCommand command = new OleDbCommand("SELECT CustCode,Initial,Surname,[Address 1],[Address 2],[Address 3],[Post Town],[Post Code],Telephone,Equipment.CustID AS CustID,Equipment.Manufacturer AS Manufacturer,Equipment.Model AS Model,Equipment.LastService AS LastService FROM Contacts LEFT OUTER JOIN Equipment ON Equipment.CustID = Contacts.CustID WHERE Archived = 0 AND (CustCode = '" + textBox12.Text + "' OR Initial = '" + textBox12.Text + "' OR Surname = '" + textBox12.Text + "' OR Initial = '" + textBox12.Text + "' OR [Post Town] = '" + textBox12.Text + "' OR [Post Code] = '" + textBox12 + "')", conn); OleDbDataReader Data = command.ExecuteReader(); LoopThroughRecs(Data); } finally { conn.Close(); } }

//Button 3 is to call next record

        public void button3_Click_3(object sender, EventArgs e)

        {
            System.Data.OleDb.OleDbConnection conn = new
            System.Data.OleDb.OleDbConnection();
            conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BoilerSvc_be.mdb";
            try
            {
                conn.Open();
                OleDbCommand command = new OleDbCommand("SELECT CustCode,Initial,Surname,[Address 1],[Address 2],[Address 3],[Post Town],[Post Code],Telephone,Equipment.CustID AS CustID,Equipment.Manufacturer AS Manufacturer,Equipment.Model AS Model,Equipment.LastService AS LastService FROM Contacts LEFT OUTER JOIN Equipment ON Equipment.CustID = Contacts.CustID WHERE Archived = 0 AND(CustCode LIKE '" + textBox12.Text + "' OR Initial LIKE '" + textBox12.Text + "' OR Surname LIKE '" + textBox12.Text + "' OR Initial LIKE '" + textBox12.Text + "' OR [Post Town] LIKE '" + textBox12.Text + "' OR [Post Code] LIKE '" + textBox12 + "')", conn);
                OleDbDataReader Reader = command.ExecuteReader();

                LoopThroughRecs(Reader);
            }
            finally
            {
                conn.Close();
            }
        }



Window form datagridview selected the first row from databinding source if the textBox1 send the null value but i want to set that if textBox1 send it the null value to binding source then databinding source Row selection =false

$
0
0

Window form datagridview selected the first row from databinding source if the textBox1 send the null value but i want to set that if textBox1 send it the null value to binding source then databinding source Row selection =false

and if textBox1!= null then databinding source Row selection mode =true

calling WeAPI through ASynchronous programming in windows forms not displaying response

$
0
0

Hi,

        I am trying to call or consume WebAPI through client application (Windows forms) for asynchronous calling via HTTP client. It should return a response as the no of requests for WebAPI along with time interval......

    There is no exceptions in the program.These red lines are of format basis.  Below is my code I had tried can u please check the code and send back my the solution.These is of high priority.Hope some one responds early

Source Code:

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace semVoip_TestTool
{
    public partial class Form1 : Form
    {
       
        public Form1()
        {
            InitializeComponent();
        }

        private void btn_Start_Click(object sender, EventArgs e)
        {
            //  Thread AutoUserRegistrationThread = new Thread(AutoUserRegistrationASync);
            //AutoUserRegistrationThread.CurrentCulture = CultureInfo.InvariantCulture;
            //AutoUserRegistrationThread.Name = "AutoUserRegistrationThread";
            //AutoUserRegistrationThread.Start();
            //btn_Start.IsAccessible = true;
            Console.WriteLine();

              RunASync().Wait();
        }

        public static async Task RunASync()
        {
            // Console.WriteLine("Calling the back-end API");
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://107.108.32.145/semVoIP");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            
                // //string apiBaseAddress ="http://107.108.32.145/WebApiHMACAuthentication/";
                string apiBaseAddress = "http://107.108.32.145/semVoIP/";

                CustomDelegatingHandler customDelegatingHandler = new CustomDelegatingHandler();

                //HttpClient client = HttpClientFactory.Create(customDelegatingHandler);
                //HttpResponseMessage response = await client.PostAsJsonAsync(apiBaseAddress + "API/GetUserDetails");
                HttpResponseMessage response = await client.GetAsync(apiBaseAddress + "API/GetUserDetails");

                if (response.IsSuccessStatusCode)
                {
                    string responseString = await response.Content.ReadAsStringAsync();
                    Console.WriteLine(responseString);

                    Console.WriteLine("HTTP Status: {0}, Reason {1}. Press ENTER to exit", response.StatusCode, response.ReasonPhrase);
                    Console.WriteLine();
                
                }
                else
                {

                    Console.WriteLine("Failed to call the API. HTTP Status: {0}, Reason {1}", response.StatusCode, response.ReasonPhrase);
                 }
                 
                 //using (var client = new HttpClient())
                //{
                //      client.BaseAddress = new Uri("http://107.108.32.145/semVoIP/");
                //client.DefaultRequestHeaders.Accept.Clear();
                //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                // New code:
                //HttpResponseMessage response = await client.GetAsync("api/GetUserDetails");
                //if (response.IsSuccessStatusCode)
                //{

                //}
            }

        }

        public class CustomDelegatingHandler : DelegatingHandler
        {
            //Obtained from the server earlier, APIKey MUST be stored securly and in App.Config
            private string APPId = "4d53bce03ec34c0a911182d4c228ee6c";
            private string APIKey = "A93reRTUJHsCuQSHR+L3GxqOJyDmQpCgps102ciuabc=";


            protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
            {

                HttpResponseMessage response = null;
                string requestContentBase64String = string.Empty;

                string requestUri = System.Web.HttpUtility.UrlEncode(request.RequestUri.AbsoluteUri.ToLower());

                string requestHttpMethod = request.Method.Method;

                //Calculate UNIX time
                DateTime epochStart = new DateTime(1970, 01, 01, 0, 0, 0, 0, DateTimeKind.Utc);
                TimeSpan timeSpan = DateTime.UtcNow - epochStart;
                string requestTimeStamp = Convert.ToUInt64(timeSpan.TotalSeconds).ToString();

                //create random nonce for each request
                string nonce = Guid.NewGuid().ToString("N");

                //Checking if the request contains body, usually will be null wiht HTTP GET and DELETE
                if (request.Content != null)
                {
                    byte[] content = await request.Content.ReadAsByteArrayAsync();
                    MD5 md5 = MD5.Create();
                    //Hashing the request body, any change in request body will result in different hash, we'll incure message integrity
                    byte[] requestContentHash = md5.ComputeHash(content);
                    requestContentBase64String = Convert.ToBase64String(requestContentHash);
                }

                //Creating the raw signature string
                //string signatureRawData = String.Format("{0}{1}{2}{3}{4}{5}", APPId, requestHttpMethod, requestUri, requestTimeStamp, nonce, requestContentBase64String);
                string signatureRawData = "SEMVOIP";

                var secretKeyByteArray = Convert.FromBase64String(APIKey);

                byte[] signature = Encoding.UTF8.GetBytes(signatureRawData);

                using (HMACSHA256 hmac = new HMACSHA256(secretKeyByteArray))
                {
                    byte[] signatureBytes = hmac.ComputeHash(signature);
                    string requestSignatureBase64String = Convert.ToBase64String(signatureBytes);
                    //Setting the values in the Authorization header using custom scheme (amx)
                    // request.Headers.Authorization = new AuthenticationHeaderValue("amx", string.Format("{0}:{1}:{2}:{3}", APPId, requestSignatureBase64String, nonce, requestTimeStamp));
                    request.Headers.Authorization = new AuthenticationHeaderValue("amx", APPId + ":" + requestSignatureBase64String + ":9768b26d0560483bafb6d58afe6fa1b3:1469014188");
                }

                response = await base.SendAsync(request, cancellationToken);
                return response;
            }
        }
    }
}

populating a datagrid from a textbox search

$
0
0

Hie

I have a text box and search button, when I search for a record I get the correct record the first time, but when I search again I get results from my first search and second search. If i keep searching the results keep accumulating instead of populating the datagrid with only the current search results. How do i go about populating the datagrid with only the current search results.

my is as follows

Private Sub cmdSearch_Click(sender As Object, e As EventArgs) Handles cmdSearch.Click
        provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="

        dataFile = "C:\Users\SaNonozaa\Documents\Installations.accdb"

        connString = provider & dataFile
        If myConnection.State = ConnectionState.Closed Then
            myConnection.ConnectionString = connString
            myConnection.Open()

        End If

        Dim dt As New DataTable
        Dim adp As New OleDb.OleDbDataAdapter("SELECT * FROM Computers WHERE [BrandCPU]= '" & txtSearch.Text & "' ", myConnection)

        adp.Fill(dts, "View_Database")
        dt = dts.Tables("View_Database")
        Dim dv As New DataView(dts.Tables("View_Database"))
        dv.Sort = "BrandCPU"

        EquipDataGrid.DataSource = dv

        myConnection.Close()

    End Sub


Window form datagridview selected the first row

$
0
0

Window form datagridview selected the first row from databinding source if the textBox1 send the null value but i want to set that if textBox1 send it the null value to binding source then databinding source Row selection =false

and if textBox1!= null then databinding source Row selection mode =true


Merge datagridview row and column cells

$
0
0
how to merge datagridview row and column cells like below image...i need like that only..

Mankatha

Datagridview combobox problem

$
0
0
I have a datagridview with a combobox column that is bound to another table. When a user changes the combobox text I would like the underlying datasource to change as well how would that work if the combobox column is bound to another table as well?

Debra has a question

Datagrid user add item in bound collection

$
0
0
Is there a way to prevent the instantiation of a data grid row item until all the fields have been validated? Currently I create a data grid with predefined columns, BindingList<T>{ AllowNew = true } and then set the data source on the data grid equal to the binding list.

This requires a default ctor on T which of course leaves potential for uninitialized fields. Datagrid validation can prevent the erroneous commit but as T allows a new instance without initializing all its fields, properly implementing equality on T which I need in my case is burdened with all the null checks and resulting decisions etc.

Thanks!

How do I save datagridview edits back into the database through entity framework?

$
0
0
I've bound my combobox so that the value selected will appear on the datagridview. However, although the datagridview is editable, the changes made won't save back to the database even is I use db.SaveChanges(). Is there another method?
private void cboeCID_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            var CID = Convert.ToInt32(cboeCID.Text);

            using (var db = new Entities2())
            {

                var course = from c in db.Student_Course
                             where c.CID == CID
                             select new Class1
                             {
                                 SID = c.SID,
                                 Mark = c.Mark

                             };

                editDataGridView.DataSource = course.ToList();
            }

Viewing all 2535 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>