좋아 I는 다음과 같습니다 뭔가가 있습니다를 포맷 한 후 많은 이름을 가진 combox 채우기
가 난 단지 사용자가 있기 때문에 선택의 이름은 콤보 상자에 있어야 할
회사 명-1234 이 경우 대시와 그 뒤에 오는 숫자는 꼭 필요한 것은 아닙니다.
Heres는 Linq를 사용하여 데이터베이스를 쿼리 한 다음 대시 후 모든 것을 제거하지만 그 내용은 콤보 박스를 채우는 것처럼 보입니다.
using (context ctx = new context())
{
List<companyinformation> compInf = new List<companyinformation>();
var getCompanies = (from c in ctx.companyinformations
select c.name).ToList();
foreach (var n in getCompanies)
{
compInf.Add(new companyinformation() { name = Remove(n.LastIndexOf('-')) });
}
cbModClient.DataSource = compInf;
cbModClient.DisplayMember = "name";
cbModClient.SelectedIndex = -1;
};
방금이 코드를 시도했지만 완벽하게 작동했습니다. 이번에는 '-'대신 '-'를 사용했기 때문에 생각합니다.
using (context ctx = new context())
{
List<companyinformation> compInf = new List<companyinformation>(ctx.companyinformations);
var getCompanies = (from c in compInf
where c.name.Contains("-")
select c.name.Substring(0, c.name.LastIndexOf("-"))).ToList();
cbModClient.DataSource = getCompanies;
cbModClient.DisplayMember = "name";
cbModClient.SelectedIndex = -1;
};
콤보 상자의 데이터 소스를 새로 만든 목록이 아닌 원래 데이터로 설정합니다. 아마도 당신이 더 많은 설명 변수 이름을 사용하는 경우, 당신은 이것과 같은 실수를 적게 만들 것이다;) – Tergiver
글쎄, 난 mayn 것들을 변경하고 내가 생각할 수있는 모든 노력이 단순한 오타했지만 CompInf로 변경하고 여전히 아무것도 채우지 않습니다! – MDL
쿼리가 데이터를 반환하는지 확신합니까? – Tergiver