이 문제에 대한 도움을 얻으 려하면 텍스트 상자가있는 Datagrid에서 특정 날짜를 찾으려고합니다. 날짜는 현재 dd/MM/yyyy 형식의 문자열입니다. 날짜 열에. 전에 게시했지만 유용한 답변이없고 내 질문이 묻혔습니다. 아무도 그 주제를 피할 수있는 대답을 가진 것처럼 보이지 않습니다. 현재 응용 프로그램의 나머지 형식 때문에 DateTime 같은 날짜를 가질 수 없습니다.DataGrid 날짜 문자열 필터
감사
편집 코드 : 데이터 그리드의 범주를 찾을 때 내가 사용
public class ImagesInfo
{
public string FileName { get; set; } //For Picture File Name
public string Description { get; set; } //For the Description of the Picture
public string Category { get; set; } //Category of Picture
public string Date { get; set; }//Date Taken of the Picture, format discussed in report.
public string Comments { get; set; } //Comments for the picture
}
코드입니다.
if (categoryFilterBox.Text == string.Empty)
{
//used if nothing is in the filter box to avoid blanking
var source = new BindingSource();
source.DataSource = images;
navigationGrid.DataSource = source;
}
else
{
//making a new filtered list that includes the matching Categorys and binding it.
string catFilter;
try
{
catFilter = categoryFilterBox.Text;
var filteredList = images.Where(item => item.Category == catFilter);
var filterSource = new BindingSource();
filterSource.DataSource = filteredList;
navigationGrid.DataSource = filterSource;
}
catch (FormatException)
{
MessageBox.Show("Must be Words of Letters");
}
}
DataGrid의 원본 인 내 목록에 레코드가 추가되는 예입니다.
private void addRecord()
{
var newImage = new ImagesInfo();//new instance
newImage.FileName = fileNameTextBox.Text;
newImage.Category = categoryComboBox.Text;
//try catch for input of the date
try
{
newImage.Date = dateTakenTextBox.Text;
}
catch (FormatException)
{
MessageBox.Show("Date Not Correct Format");
}
try
{
newImage.Description = descriptionTextBox.Text;
}
catch (FormatException)
{
MessageBox.Show("Must user letters and words");
}
try
{
newImage.Comments = commentsTextBox.Text;
}
catch (FormatException)
{
MessageBox.Show("Must use letters and words");
}
images.Add(newImage);//Add instance to the main list
if (editCheckBox.Checked)
{
//Binding the new updated list to the datagrid
var source = new BindingSource();
source.DataSource = images;
navigationGrid.DataSource = source;
}
}
편집 : 어떻게해야할까요?하지만 현재 작동하지 않는 것 같습니다.
if (startDate.Text == string.Empty)
{
var source = new BindingSource();
source.DataSource = images;
navigationGrid.DataSource = source;
}
else
{
string dateFilter = startDate.Text;
var filteredList = images.Where(item => item.Date == dateFilter);
var filterSource = new BindingSource();
filterSource.DataSource = filteredList;
navigationGrid.DataSource = filterSource;
}
가 더 좋을 것이다. 게시 해주세요. –
더 많은 코드가 필요하면 코드가 추가되었습니다. – user3330371
하나의 질문을 드리겠습니다. 정확히 무엇이 문제입니까? 문자열과 관련된 날짜에 문제가 있음을 확인했습니다. 그러나, 나는 특정 날짜를 찾으려고 어디로 가지 않았어? 감사합니다 – Christos