Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I has the followinng code to make update of more control refers to the same variable on windows form.

I make it to update more than one control by asingle operation on update datatable.

This working very well on Window, calling UpdateControlValue by BeginInvoke.Action from main form. When I execute this code by mono on linux on raspian, it does't work. Thank's for help

What I have tried:

<pre>
 DataSet ds = new DataSet();
DataTable tabella1 = new DataTable(TABLE_NAME);
private const string TABLE_NAME = "CostantTable";
private const string COLUMN_NAME = "CtrlName";
private const string COLUMN_VALUE = "CtrlValue";
     
     public HmiMappingManager()
     {            
         tabella1.Columns.Add(COLUMN_NAME, typeof(string));
         tabella1.Columns.Add(COLUMN_VALUE, typeof(string));
         
         var values = Enum.GetValues(typeof(ControlMapEnum));

         foreach (var val in values)
         {
             string defaultValue = DecorationHelper.GetDescription((ControlMapEnum)Enum.Parse(typeof(ControlMapEnum), val.ToString()));
             tabella1.Rows.Add(new object[2] { val.ToString(), defaultValue });
         }

         ds.Tables.Add(tabella1);
         ds.AcceptChanges();
     }
           
     public void AssignConstantToControl(List<System.Windows.Forms.Control> controlToAssociate, ControlMapEnum controlId)
     {           
         BindingSource bs1 = new BindingSource();
         bs1.DataSource = ds;
         bs1.DataMember = TABLE_NAME;
         bs1.Filter = COLUMN_NAME + " = '" + controlId.ToString() + "'";

         foreach (System.Windows.Forms.Control control in controlToAssociate)
             control.DataBindings.Add("Text", bs1, COLUMN_VALUE);

     }
     
   
     public void UpdateControlValue(ControlMapEnum controlId, string newValue)
     {            
             DataRow dr = tabella1.Select(COLUMN_NAME + " = '" + controlId.ToString() + "'").FirstOrDefault();

             if (dr == null)
                 return;

             int index = tabella1.Rows.IndexOf(dr);

             tabella1.Rows[index].BeginEdit();
             tabella1.Rows[index][COLUMN_VALUE] = newValue;
             tabella1.Rows[index].EndEdit();               
             LoggerManagerUtility.Instance.Log(LogLevel.Info, this, "END UPDATE CONTROL" + controlId + " TEXT TO VISUALIZE: " + newValue);

         
     }
Posted
Updated 16-Aug-22 23:31pm
Comments
Richard Deeming 17-Aug-22 5:29am    
"It doesn't work" tells us precisely nothing.

Click the green "Improve question" link and update your question to include a clear and complete description of the problem, including the full details of any errors.
Valentina82 17-Aug-22 5:32am    
The text does't update on the two control when i proove. In window, it work very good.
Dave Kreskowiak 17-Aug-22 11:42am    
You need to narrow down which part of this process is failing. Is it something in this code or is it something in the database code that generates the data for this code to use?

Nobody can do that for you.
Valentina82 18-Aug-22 2:16am    
There are no database, datatable is setting by hand in the constructor, by anumerate. Than I assign to each control an identify and in the method UpdateControlValue I update the value associated to control. Here there is a problem. In windows OS it work very well. Than in mono it doesn't work. Or better on the first time work, on the inizialization of form, than nothing more.
Dave Kreskowiak 18-Aug-22 11:03am    
Again, you have to run this code under the debugger to narrow down exactly what part of it is failing. Nobody can do that for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900