I have a Datagridview and Textbox . Datagridview have column ' PublishYear ' with type number only. I'm binding that column to Textbox as bellow:
txtPublishYear.DataBindings.Add("Text", dataGridview.DataSource, "PublishYear", true, DataSourceUpdateMode.OnPropertyChanged, "", $"Năm {0}");
Textbox listen data of Datagridview working. But I can't update data of grid when text of Textbox change. How can i fix this? Thanks.
Here is the solution ...
Binding bd = txtPublishYear.DataBindings.Add("Text", dataGridview.DataSource, "PublishYear", true, DataSourceUpdateMode.OnValidation, "", $"Năm {0}");
bd.Parse += new ConvertEventHandler(CurrencyStringToNumber);
...
private void CurrencyStringToNumber(object sender, ConvertEventArgs cevent)
{
if (cevent.DesiredType != typeof(Int16)) return;
string result = Regex.Match(txtPublishYear.Text, @"\d+").Value;
cevent.Value = int.Parse(result,NumberStyles.Currency, null);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.