none
Change the color of a control when the bound field's data is changed RRS feed

  • Question

  • Hello !

    I have a BindingSource , and some control bound to it.

    Sometimes the data on bindingsource is changed

    How can I do that when the data of current object on bindingSource is updated , the corresponding controls in the form bound to changed fields  change the background color for example to Red?

    I know that there's an event BindingSource.CurrentItemChanged that is fired when the changes are made.

    But how can I find the fields that have changed , and the control that is bound to this field ?

    Thank you ! 



    • Edited by dcode25 Friday, October 10, 2014 2:28 AM
    • Moved by KareninstructorMVP Friday, October 10, 2014 9:39 PM Moved from VB.NET forum
    Friday, October 10, 2014 2:27 AM

All replies

  • TO KEEP TRACK OF CHANGED COLOUMN add a trigger for  after update and add a column to table with changed feildsname added to it with each field column seperated by ,or ; so its easy to split when you trive .

    get column with changed field names for a record and split it for each item 

    you can use below code to change color on databound 

    protected void gvfeildStatus_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    //populate color images based on text values
                    HyperLink DrivesLink = (HyperLink)e.Row.FindControl("DrivesLink");


                    if (DrivesLink.Text == "GREEN")
                    {
                        DrivesLink.COLOR= RED;


                    }

    }

    Friday, October 10, 2014 3:44 AM
  • TO KEEP TRACK OF CHANGED COLOUMN add a trigger for  after update and add a column to table with changed feildsname added to it with each field column seperated by ,or ; so its easy to split when you trive

    Please don't post C code in the VB forum - it is confusing to people who use the responses in the thread to obtain infomration about their problem.

    Friday, October 10, 2014 6:08 AM
  • sorry , but how to keep track of changed column , because I don't know which column is changed in the bindingsource current item.
    Friday, October 10, 2014 4:30 PM
  • For that you use the databinding events take a look at this tip on our website.

    http://www.vb-tips.com/DataBindingEvents.aspx


    Success
    Cor

    Friday, October 10, 2014 4:56 PM
  • Hello !

    I have a BindingSource , and some control bound to it.

    Sometimes the data on bindingsource is changed

    How can I do that when the data of current object on bindingSource is updated , the corresponding controls in the form bound to changed fields  change the background color for example to Red?

    I know that there's an event BindingSource.CurrentItemChanged that is fired when the changes are made.

    But how can I find the fields that have changed , and the control that is bound to this field ?

    Thank you ! 



    First you say you have a control bound to a Bindingsource.

    Then you say you want corresponding controls bound to changed fields to change their backcolor if the data of the current object on the bindingsource is updated.

    Since I don't know how to bind various controls to fields of a bindingsources source then I've no idea how to assist you with this.

    On the other hand if you could paste your code into a code block showing how this is done so I could simulate it I figure that I could figure out how to do it. As long as you paste all the code necessary to do it in a code block.


    La vida loca

    Friday, October 10, 2014 5:08 PM
  • Hello,

    If the BindingSource had a DataTable as it's DataSource then you could use DataTable events to detect which field changed. If the BindingSource is using a different source then this will not work.

    See my MSDN article Working with DataTable events primer for demonstrations for ColumnChanging, ColumnChanged, RowChanged, RowDeleted, RowDeleting, TableNewRow. Now in the article project I am using a DataGridView and not changing any background colors but the image below shows a modified version I just did that adds a column which is displayed read-only and when a column value changes I update that column

    I changed Sheet to Sheet1 in row 3, column 1, note the DataGridView on the bottom show the triggered events. I don't show the column/field name but that is easy; e.Column.ColumnName in ColumnChanging event.

    With the fundamentals in the article you can determine

    1. value for change
    2. original value prior to change
    3. column/field name

    So with this information if say FirstName field was bound to txtFirstName TextBox in the Columninging or ColumnChanged event you can change the colors of the TextBox.

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Friday, October 10, 2014 5:39 PM
  • The bindingsource is related to an entity ( I'm using entity framework)
    Friday, October 10, 2014 5:44 PM
  • I don't know anything about entity.

    However these two links seem to have code in C#, which can be converted to VB easily using an online converter like Telerik, and I think from reading the articles can make entity into a datatable which then using Kevininstructor's methods at the link he provides I suppose would work maybe.

    Working with Entities instead of DataTable Objects...

    Custom ORM - Map your entity with DataSet/DataTable/DataReader


    La vida loca


    Friday, October 10, 2014 6:38 PM
  • it's easy to do that with Datagridview , I want to do with single controls like : a textbox , a combobox , a checkbox...etc.

    Because on datagridview , all the columns , rows , cells are part of the same control.

    Friday, October 10, 2014 7:18 PM
  • Did you know there were more persons replying to your message than the last one. 

    For sure you reply tells that you ignore those all.

    Have a nice day.


    Cor


    Friday, October 10, 2014 7:41 PM
  • You are wrong.

    Just look at my posts .I reply to all the persons that give a solution to me.

    I don't have any intention to ignore the persons, because I want to resolve my problem and not to joke.

    Thank you !

    Friday, October 10, 2014 7:55 PM
  • The bindingsource is related to an entity ( I'm using entity framework)
    Since you are using Entity Framework I am moving this thread to the Entity Framework forum.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Friday, October 10, 2014 9:39 PM
  • The bindingsource is related to an entity ( I'm using entity framework)

    Since you are using Entity Framework I am moving this thread to the Entity Framework forum.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Kevin,

    This question is not in particular for the entity framework, he uses probably also a keyboard but therefore it does not become a keyboard question. Asked is a VB solution, not one in C++. If your knowledge is not enough to answer the question is not a reason to move it because you have read the words "Entity Framework". DataBinding is done by the BindingContext not by the entityframework. It is depending which type of control is used but mainly they use this.

    http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingcontext(v=vs.110).aspx

     


    Success
    Cor


    Saturday, October 11, 2014 8:28 AM
  • You are wrong.

    Just look at my posts .I reply to all the persons that give a solution to me.

    I don't have any intention to ignore the persons, because I want to resolve my problem and not to joke.

    Thank you !

    I see an event which is raised if a bound value is changed is not a solution for you to be able to change the color.

    Yea then there is only one solution for you. "Hire a programmer".



    Success
    Cor

    Saturday, October 11, 2014 8:30 AM
  • The bindingsource is related to an entity ( I'm using entity framework)

    Since you are using Entity Framework I am moving this thread to the Entity Framework forum.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Kevin,

    This question is not in particular for the entity framework, he uses probably also a keyboard but therefore it does not become a keyboard question. Asked is a VB solution, not one in C++. If your knowledge is not enough to answer the question is not a reason to move it because you have read the words "Entity Framework". DataBinding is done by the BindingContext not by the entityframework. It is depending which type of control is used but mainly they use this.

    http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingcontext(v=vs.110).aspx

     


    Success
    Cor


    Greetings Cor and thanks for your reply,

    This is not about my knowledge in regards to Entity Framework for moving the thread . My reason for moving this thread is to get more eyes on the question, that is it.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

    Saturday, October 11, 2014 1:05 PM
  • Hey Cor !

    I don't know what is your role in this forum. to help people find a solution , or to try to close cases with discussion out of case.

    Ok , I agree with you to Hire a programmer. I think to hire you. But before hiring people , they must show they are good for a job. So as a test for you , please resolve this problem and post the code here , so I can decide to hiring you.

    the time start ... Now.

    Saturday, October 11, 2014 2:28 PM
  • Hey DCode

    Look at my sample and give at least a comment about it why it is not working instead of giving this kind of replies. Be aware, you cannot hire me, sorry for you.

    Of course I don't fall in that trick of proofing, there is nothing to proof, Microsoft has already done that. 


    Success
    Cor

    Saturday, October 11, 2014 3:16 PM
  • Sorry , but your posts here contains only words and links. not a single line of code.

    Those links can be found everywhere in the intrnet. Post a code according to my problem , and not a link where there's nothing related about my case. Did you test-it that link ? |If not why you are giving yo me as a solution ?

    And since Microsoft has already done that , please write some code here about my problem , it's easy to give a link , or if you don't know how to resolve this problem, don't write and do other things.

     
    Saturday, October 11, 2014 3:30 PM
  • Sorry , but your posts here contains only words and links. not a single line of code.

    Those links can be found everywhere in the intrnet. Post a code according to my problem , and not a link where there's nothing related about my case. Did you test-it that link ? |If not why you are giving yo me as a solution ?

    And since Microsoft has already done that , please write some code here about my problem , it's easy to give a link , or if you don't know how to resolve this problem, don't write and do other things.

     

    Strange, the link to our website of the binding events is very rare on Internet. Beside that it contains only code. But if you don't understand it or are not able to try it. Then you know I had already taken an earlier conclusion.


    Success
    Cor

    Saturday, October 11, 2014 3:35 PM
  • ok , can you tell me which part of your code try to find the control that is bound to the changed field in the bindingsource ? Please write here this code.

    Thank you !


    • Edited by dcode25 Saturday, October 11, 2014 11:00 PM
    Saturday, October 11, 2014 4:13 PM