WinForm과 그리드의 콤보 박스 열에 관계형 데이터를 표시하는 DataGridView로 비슷한 문제가 발생했습니다. 열을 정렬하고 싶지만 정렬은 DisplayMember (표시되는 텍스트 필드)가 아닌 ValueMember (int ID 필드)로 정렬됩니다. 입력 된 데이터 집합을 사용하여 해당 형식이 지정된 테이블을 DataView에 배치하고 해당 DataView를 BindingSource의 데이터 소스로 사용합니다.이 데이터 소스는 그리드의 데이터 소스였습니다. :-)
웹에서 여러 게시물을 읽은 후 나에게 도움이 된 해결책은 다음과 같습니다. Typed 데이터 세트의 코드 숨김에서 기본 입력 테이블의 Typed Row에 사용자 정의 속성을 추가했습니다. .
예 : 내 입력 데이터 집합의 인스턴스가있는의 WinForm의 코드 숨김에서
public string ProvinceAtRow
{
get
{
string result = string.Empty;
if (!this.CustomerInfoRow.IsProvinceDescriptionNull())
{
result = this.CustomerInfoRow.ProvinceDescription;
}
return result;
}
}
다음으로,이 유형이 지정된 테이블에 DataColumn에 추가. 예 (의 WinForm의로드 이벤트 코드) 데이터 세트의 데이터가있는 경우
this.DSGrowth.LocalGrowthFactor.Columns.Add(
new DataColumn("Province", typeof(string)));
다음에 첨가하고, 컬럼 (들)을 작성한다. 예 :
//if we have data then have to fill in the colums we added to the TDS
if (this.DSGrowth.LocalGrowthFactor.Rows.Count > 0)
{
//fill columns so that can display on datagrid as columns that can be sorted
// ref http://www.daniweb.com/forums/thread283915.html
Array.ForEach<dsLocalGrowthFactor.LocalGrowthFactorRow>( this.DSGrowth.LocalGrowthFactor.Rows.OfType<dsLocalGrowthFactor.LocalGrowthFactorRow>().ToArray(),
row =>
{
row["Province"] = row.ProvinceAtRow;
}
);
//accept changes on TDS so not to be prompted to save changes
this.DSGrowth.AcceptChanges();
}
//set default sort
DataView dvFactors = new DataView(this.DSGrowth.LocalGrowthFactor);
dvFactors.Sort = "GrowthFactor DESC";
this.BSLocalGrowth.DataSource = dvFactors;
this.DgvGrowth.DataSource = this.BSLocalGrowth;
if (this.DgvGrowth.Rows.Count > 0)
{
//select first row
this.BSLocalGrowth.MoveFirst();
this.DgvGrowth.Rows[0].Selected = true;
}
더 이상 ComboBox 열과 정렬이 작동하지 않습니다!
희망이 있으면 비슷한 상황에있는 모든 사람들이 도움이되기를 바랍니다.
답장을 보내 주셔서 감사합니다. 나는 그것을 시도했고 그 해결책은 내가 편집 된 초기 게시물에서 설명했던 동기들에 대해 나를 위해 작동하지 않는다. –